From 82b068289c12bc5876f17b4c80274ccf8eba6062 Mon Sep 17 00:00:00 2001 From: Judit Knoll Date: Wed, 11 Oct 2023 11:35:43 +0200 Subject: [PATCH] recreate issue --- .../detect/FindOverridableMethodCallTest.java | 36 +++++++++++++++++++ .../java/overridableMethodCall/Issue2414.java | 18 ++++++++++ spotbugsTestCases/src/java17/Issue2414.java | 17 +++++++++ 3 files changed, 71 insertions(+) create mode 100644 spotbugsTestCases/src/java/overridableMethodCall/Issue2414.java create mode 100644 spotbugsTestCases/src/java17/Issue2414.java diff --git a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCallTest.java b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCallTest.java index a764a865f21..d14bde91ec6 100644 --- a/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCallTest.java +++ b/spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/FindOverridableMethodCallTest.java @@ -3,6 +3,9 @@ import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; import static org.hamcrest.Matchers.hasItem; +import edu.umd.cs.findbugs.BugCollection; +import edu.umd.cs.findbugs.test.SpotBugsExtension; +import edu.umd.cs.findbugs.test.SpotBugsRunner; import org.apache.bcel.Const; import static org.hamcrest.MatcherAssert.assertThat; @@ -13,8 +16,41 @@ import edu.umd.cs.findbugs.annotations.Confidence; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; +import org.junit.jupiter.api.condition.DisabledOnJre; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.api.extension.ExtendWith; +import java.nio.file.Paths; + +@ExtendWith(SpotBugsExtension.class) class FindOverridableMethodCallTest extends AbstractIntegrationTest { + @Test + @DisabledOnJre({ JRE.JAVA_8 }) + void testIssue2414_java11(SpotBugsRunner spotbugs) { + BugCollection bugCollection = spotbugs.performAnalysis(Paths.get( + "../spotbugsTestCases/build/classes/java/java17/overridableMethodCall/Issue2414.class")); + + final BugInstanceMatcher bugInstanceMatcher = new BugInstanceMatcherBuilder() + .bugType("MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR") + // .inClass("Issue2414") + // .inMethod(Const.CONSTRUCTOR_NAME) + // .withConfidence(Confidence.LOW) + // .atLine(line) + .build(); + + assertThat(bugCollection, containsExactly(1, bugInstanceMatcher)); + } + + @Test + void testIssue2414_java8() { + performAnalysis("overridableMethodCall/Issue2414.class"); + + final BugInstanceMatcher bugInstanceMatcher = new BugInstanceMatcherBuilder() + .bugType("MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR") + .build(); + + assertThat(getBugCollection(), containsExactly(0, bugInstanceMatcher)); + } @Test void testDirectCase() { diff --git a/spotbugsTestCases/src/java/overridableMethodCall/Issue2414.java b/spotbugsTestCases/src/java/overridableMethodCall/Issue2414.java new file mode 100644 index 00000000000..43cfc6cce92 --- /dev/null +++ b/spotbugsTestCases/src/java/overridableMethodCall/Issue2414.java @@ -0,0 +1,18 @@ +package overridableMethodCall; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class Issue2414 { + private final static List aList = Collections.unmodifiableList(Arrays.asList("de", "us")); + + public Issue2414() { + getList(); + } + + private void getList() { + aList.stream() + .forEach(test -> test.length()); + } +} \ No newline at end of file diff --git a/spotbugsTestCases/src/java17/Issue2414.java b/spotbugsTestCases/src/java17/Issue2414.java new file mode 100644 index 00000000000..f266385cf34 --- /dev/null +++ b/spotbugsTestCases/src/java17/Issue2414.java @@ -0,0 +1,17 @@ +package overridableMethodCall; + +import java.util.List; +import java.util.stream.Collectors; + +public class Issue2414 { + private final static List aList = List.of("de", "us"); + + public Issue2414() { + getList(); + } + + private void getList() { + aList.stream() + .forEach(test -> test.length()); + } +} \ No newline at end of file