forked from spotbugs/spotbugs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: reproducer for issue spotbugs#2793
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue2793Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package edu.umd.cs.findbugs.detect; | ||
|
||
import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.DisabledOnJre; | ||
import org.junit.jupiter.api.condition.JRE; | ||
|
||
import edu.umd.cs.findbugs.AbstractIntegrationTest; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; | ||
|
||
class Issue2793Test extends AbstractIntegrationTest { | ||
|
||
@Test | ||
@DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 }) | ||
void testRecordSerialVersionUid() { | ||
performAnalysis("../java17/ghIssues/Issue2793$RecordWithoutSerialVersionUid.class"); | ||
|
||
assertBugCount("SE_NO_SERIALVERSIONID", 0); | ||
} | ||
|
||
@Test | ||
@DisabledOnJre({ JRE.JAVA_8, JRE.JAVA_11 }) | ||
void testExternalizableRecord() { | ||
performAnalysis("../java17/ghIssues/Issue2793$ExternalizableRecord.class"); | ||
|
||
assertBugCount("SE_NO_SUITABLE_CONSTRUCTOR_FOR_EXTERNALIZATION", 0); | ||
} | ||
|
||
private void assertBugCount(String type, int expectedCount) { | ||
BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() | ||
.bugType(type) | ||
.build(); | ||
|
||
assertThat(getBugCollection(), containsExactly(expectedCount, bugMatcher)); | ||
} | ||
|
||
private void assertBugCount(int expectedCount) { | ||
BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder() | ||
.build(); | ||
|
||
assertThat(getBugCollection(), containsExactly(expectedCount, bugMatcher)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ghIssues; | ||
|
||
import java.io.Externalizable; | ||
import java.io.IOException; | ||
import java.io.ObjectInput; | ||
import java.io.ObjectOutput; | ||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class Issue2793 { | ||
public record RecordWithoutSerialVersionUid(int x, int y, String message) implements Serializable { | ||
|
||
} | ||
|
||
public record ExternalizableRecord(int x, int y, String message) implements Externalizable { | ||
public void writeExternal(ObjectOutput out) throws IOException { | ||
|
||
} | ||
|
||
public void readExternal(ObjectInput in) throws IOException { | ||
|
||
} | ||
} | ||
} |