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.
HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS not reported for so…
…me classes (spotbugs#2538) * test: issue spotbugs#2402 reproducer HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS is reported for TestA, TestC and TestD, not for TestB * fix: store potential bugs by class name and bug type Updated the key for potential bugs from only the class name to also the bug type. * removed commented out code * applied spotless
- Loading branch information
Showing
7 changed files
with
166 additions
and
9 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
spotbugs-tests/src/test/java/edu/umd/cs/findbugs/ba/Issue2402Test.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,32 @@ | ||
package edu.umd.cs.findbugs.ba; | ||
|
||
import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
import edu.umd.cs.findbugs.AbstractIntegrationTest; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; | ||
import edu.umd.cs.findbugs.SortedBugCollection; | ||
|
||
public class Issue2402Test extends AbstractIntegrationTest { | ||
|
||
@Test | ||
public void test() { | ||
performAnalysis("ghIssues/issue2402/TestA.class", | ||
"ghIssues/issue2402/TestA$UMap.class", | ||
"ghIssues/issue2402/TestB.class", | ||
"ghIssues/issue2402/TestB$UMap.class", | ||
"ghIssues/issue2402/TestC.class", | ||
"ghIssues/issue2402/TestC$UMap.class", | ||
"ghIssues/issue2402/TestD.class", | ||
"ghIssues/issue2402/TestD$UMap.class"); | ||
|
||
BugInstanceMatcher bugTypeMatcher = new BugInstanceMatcherBuilder().bugType("HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS").build(); | ||
|
||
SortedBugCollection bugCollection = (SortedBugCollection) getBugCollection(); | ||
assertThat(bugCollection, containsExactly(4, bugTypeMatcher)); | ||
} | ||
|
||
} |
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
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,22 @@ | ||
package ghIssues.issue2402; | ||
import java.util.HashMap; | ||
public class TestA { | ||
static class UMap extends HashMap<TestA, String> {} | ||
; | ||
static HashMap<TestA, String> m = | ||
new HashMap<TestA, String>(); | ||
|
||
static int foo(HashMap<TestA, String> map) { | ||
return map.size(); | ||
} | ||
@Override | ||
public boolean equals(Object o) { | ||
return hashCode() == o.hashCode(); | ||
} | ||
public static String add(TestA b, String s) { | ||
return m.put(b, s); | ||
} | ||
public static String get(TestA b) { | ||
return m.get(b); | ||
} | ||
} |
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,22 @@ | ||
package ghIssues.issue2402; | ||
import java.util.HashMap; | ||
public class TestB { | ||
static class UMap extends HashMap<TestB, String> {} | ||
; | ||
static HashMap<TestB, String> m = | ||
new HashMap<TestB, String>(); | ||
|
||
static int foo(HashMap<TestB, String> map) { | ||
return map.size(); | ||
} | ||
@Override | ||
public boolean equals(Object o) { | ||
return hashCode() == o.hashCode(); | ||
} | ||
public static String add(TestB b, String s) { | ||
return m.put(b, s); | ||
} | ||
public static String get(TestB b) { | ||
return m.get(b); | ||
} | ||
} |
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,22 @@ | ||
package ghIssues.issue2402; | ||
import java.util.HashMap; | ||
public class TestC { | ||
static class UMap extends HashMap<TestC, String> {} | ||
; | ||
static HashMap<TestC, String> m = | ||
new HashMap<TestC, String>(); | ||
|
||
static int foo(HashMap<TestC, String> map) { | ||
return map.size(); | ||
} | ||
@Override | ||
public boolean equals(Object o) { | ||
return hashCode() == o.hashCode(); | ||
} | ||
public static String add(TestC b, String s) { | ||
return m.put(b, s); | ||
} | ||
public static String get(TestC b) { | ||
return m.get(b); | ||
} | ||
} |
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,22 @@ | ||
package ghIssues.issue2402; | ||
import java.util.HashMap; | ||
public class TestD { | ||
static class UMap extends HashMap<TestD, String> {} | ||
; | ||
static HashMap<TestD, String> m = | ||
new HashMap<TestD, String>(); | ||
|
||
static int foo(HashMap<TestD, String> map) { | ||
return map.size(); | ||
} | ||
@Override | ||
public boolean equals(Object o) { | ||
return hashCode() == o.hashCode(); | ||
} | ||
public static String add(TestD b, String s) { | ||
return m.put(b, s); | ||
} | ||
public static String get(TestD b) { | ||
return m.get(b); | ||
} | ||
} |