diff --git a/infer/tests/codetoanalyze/java/crashcontext/BUCK b/infer/tests/codetoanalyze/java/crashcontext/BUCK index ba9f4fae4..aa6cdebbe 100644 --- a/infer/tests/codetoanalyze/java/crashcontext/BUCK +++ b/infer/tests/codetoanalyze/java/crashcontext/BUCK @@ -53,6 +53,11 @@ infer_cmds = [ "BranchingCallsExample", "BranchingCallsExample.java", "BranchingCallsExample.stacktrace.json" + ), + mk_infer_cmd( + "MethodNameClashExample", + "MethodNameClashExample.java", + "MethodNameClashExample.stacktrace.json" ) ] diff --git a/infer/tests/codetoanalyze/java/crashcontext/MethodNameClashExample.java b/infer/tests/codetoanalyze/java/crashcontext/MethodNameClashExample.java new file mode 100644 index 000000000..c09829b30 --- /dev/null +++ b/infer/tests/codetoanalyze/java/crashcontext/MethodNameClashExample.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package codetoanalyze.java.crashcontext; + +public class MethodNameClashExample { + + public static class A { + + public static void foo() { + String s = null; + s.toString(); + } + + } + + public static class B { + + public static void foo() { + A.foo(); + } + + } + + public static void main(String[] args) { + B.foo(); + } + +} diff --git a/infer/tests/codetoanalyze/java/crashcontext/MethodNameClashExample.stacktrace.json b/infer/tests/codetoanalyze/java/crashcontext/MethodNameClashExample.stacktrace.json new file mode 100644 index 000000000..fda7fc31f --- /dev/null +++ b/infer/tests/codetoanalyze/java/crashcontext/MethodNameClashExample.stacktrace.json @@ -0,0 +1 @@ +{"exception_type": "java.lang.NullPointerException", "stack_trace": ["at codetoanalyze.java.crashcontext.MethodNameClashExample$A.foo(MethodNameClashExample.java:18)","at codetoanalyze.java.crashcontext.MethodNameClashExample$B.foo(MethodNameClashExample.java:26)","at codetoanalyze.java.crashcontext.MethodNameClashExample.main(MethodNameClashExample.java:32)",""], "exception_message": "", "normvector_stack": ["codetoanalyze.java.crashcontext.MethodNameClashExample$A.foo","codetoanalyze.java.crashcontext.MethodNameClashExample$B.foo","codetoanalyze.java.crashcontext.MethodNameClashExample.main"]} diff --git a/infer/tests/endtoend/java/crashcontext/MethodNameClashTest.java b/infer/tests/endtoend/java/crashcontext/MethodNameClashTest.java new file mode 100644 index 000000000..5976ef090 --- /dev/null +++ b/infer/tests/endtoend/java/crashcontext/MethodNameClashTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +package endtoend.java.crashcontext; + +import static org.hamcrest.MatcherAssert.assertThat; + +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; + +import utils.CrashContextResults; + +public class MethodNameClashTest { + + public static final String TAG = "MethodNameClashExample"; + + public static final String MAIN_METHOD = + "codetoanalyze.java.crashcontext.MethodNameClashExample.main(java.lang.String[]):void"; + + public static final String A_FOO_METHOD = + "codetoanalyze.java.crashcontext.MethodNameClashExample$A.foo():void"; + + public static final String B_FOO_METHOD = + "codetoanalyze.java.crashcontext.MethodNameClashExample$B.foo():void"; + + private static CrashContextResults crashcontext; + + @BeforeClass + public static void loadResults() throws IOException { + crashcontext = + CrashContextResults.loadJSONResults(TAG); + } + + @Test + public void shapeOfTheStack() { + assertThat("The stack trace should contain " + A_FOO_METHOD, + crashcontext.hasStackFrame(A_FOO_METHOD, 0)); + assertThat("The stack trace should contain " + B_FOO_METHOD, + crashcontext.hasStackFrame(B_FOO_METHOD, 1)); + assertThat("The stack trace should contain " + MAIN_METHOD, + crashcontext.hasStackFrame(MAIN_METHOD, 2)); + } + +}