Skip to content

Commit

Permalink
recreate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JuditKnoll committed Oct 12, 2023
1 parent d5d5a87 commit 6429043
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,8 +16,45 @@
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")
// .inClass("Issue2414")
// .inMethod(Const.CONSTRUCTOR_NAME)
// .withConfidence(Confidence.LOW)
// .atLine(line)
.build();

assertThat(getBugCollection(), containsExactly(0, bugInstanceMatcher));
}

@Test
void testDirectCase() {
Expand Down
26 changes: 26 additions & 0 deletions spotbugsTestCases/src/java/overridableMethodCall/Issue2414.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package overridableMethodCall;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Issue2414 {
private final static List<String> aList = new ArrayList<>(Arrays.asList("de", "us"));

public Issue2414() {
getList();
}

private List<String> getList() {

return aList.stream()
// if this peek is commented, it works
.peek(test -> {
if (test.length() != 2) {
throw new IllegalStateException("foobar");
}
})
.collect(Collectors.toList());
}
}
23 changes: 23 additions & 0 deletions spotbugsTestCases/src/java17/Issue2414.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package overridableMethodCall;

import java.util.List;
import java.util.stream.Collectors;

public class Issue2414 {
private final static List<String> aList = List.of("de", "us");

public Issue2414() {
getList();
}

private List<String> getList() {
return aList.stream()
// if this peek is commented, it works
.peek(test -> {
if (test.length() != 2) {
throw new IllegalStateException("foobar");
}
})
.collect(Collectors.toList());
}
}

0 comments on commit 6429043

Please sign in to comment.