From 4ba1c41e8a698ed67e8f262412e1fef7a09c5d17 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Sun, 13 Dec 2015 13:32:47 +0900 Subject: [PATCH] Exclude "METHOD_CALLED" references from consideration as a bug's principal location. --- prod/net/jaekl/cfb/store/Location.java | 2 + prod/net/jaekl/cfb/xml/BugInstance.java | 16 ++++- test/net/jaekl/cfb/xml/BugInstanceTest.java | 77 +++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 test/net/jaekl/cfb/xml/BugInstanceTest.java diff --git a/prod/net/jaekl/cfb/store/Location.java b/prod/net/jaekl/cfb/store/Location.java index 51857eb..d4d1972 100644 --- a/prod/net/jaekl/cfb/store/Location.java +++ b/prod/net/jaekl/cfb/store/Location.java @@ -8,6 +8,8 @@ import net.jaekl.cfb.xml.BugMethod; import net.jaekl.cfb.xml.SourceLine; public class Location { + public static String METHOD_CALLED = "METHOD_CALLED"; + Long m_id; String m_className; String m_methodName; diff --git a/prod/net/jaekl/cfb/xml/BugInstance.java b/prod/net/jaekl/cfb/xml/BugInstance.java index 0683a7d..b805096 100644 --- a/prod/net/jaekl/cfb/xml/BugInstance.java +++ b/prod/net/jaekl/cfb/xml/BugInstance.java @@ -212,9 +212,21 @@ public class BugInstance extends ParseResult { // This should be the place where the bug is reported. Location getPrincipalLocation() { - if (null != m_locations && m_locations.size() > 0) { - return m_locations.get(0); + if (null == m_locations) { + return null; } + + for (int idx = 0; idx < m_locations.size(); ++idx) { + Location loc = m_locations.get(idx); + if (Location.METHOD_CALLED.equals(loc.getMethodRole())) { + // METHOD_CALLED locations describe the method that is being called, + // but the bug is located in the caller, not in the callee. + // Thus, ignore this information about the callee. + continue; + } + return loc; + } + return null; } diff --git a/test/net/jaekl/cfb/xml/BugInstanceTest.java b/test/net/jaekl/cfb/xml/BugInstanceTest.java new file mode 100644 index 0000000..b7e98fb --- /dev/null +++ b/test/net/jaekl/cfb/xml/BugInstanceTest.java @@ -0,0 +1,77 @@ +package net.jaekl.cfb.xml; + +import static org.junit.Assert.*; + +import net.jaekl.cfb.store.Location; + +import org.junit.Test; + +public class BugInstanceTest { + + @Test + public void testGetPrincpalLocation() { + Location[][][] data = + { + { + // Location(Long id, String className, String methodName, String methodRole, Integer startLine, Integer endLine) + { + // input + new Location( 1L, "ClassOne", "methodOne", "METHOD_CALLED", 1, 12), + new Location( 2L, "ClassTwo", "methodTwo", "", 23, 34) + }, + { + // expected result + new Location( 2L, "ClassTwo", "methodTwo", "", 23, 34) + } + }, + { + { + // input: empty set + }, + { + // expected result + null + } + }, + { + { + // input + new Location( 3L, "ClassThree", "methodThree", null, 34, 45), + new Location( 4L, "ClassFour", "methodFour", null, 45, 56), + new Location( 5L, "ClassFive", "methodFive", null, 56, 67) + }, + { + // expected result + new Location( 3L, "ClassThree", "methodThree", null, 34, 45), + } + }, + { + { + // input + new Location( 6L, "CLassSix", "methodSix", "METHOD_CALLED", 67, 78) + }, + { + // expected result + null + } + } + }; + + for (Location[][] datum : data) { + Location[] input = datum[0]; + Location expected = datum[1][0]; + + BugInstance bug = new BugInstance( + 101L, // id + "CATEGORY", + "TYPE", + input, + new LocalVariable[0] + ); + Location actual = bug.getPrincipalLocation(); + + assertEquals(expected, actual); + } + } + +} -- 2.39.2