Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug about HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS #2402

Closed
LynnBroe opened this issue Apr 6, 2023 · 1 comment · Fixed by #2538
Closed

Bug about HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS #2402

LynnBroe opened this issue Apr 6, 2023 · 1 comment · Fixed by #2538

Comments

@LynnBroe
Copy link

LynnBroe commented Apr 6, 2023

TestA.java:

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);
    }
}

SpotBugs reported a HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS warning in the testA.java file above. But if I use SpotBugs to detect some sameTestA.java files, the results are not equivalent. SpotBugs can only report this warning in part of files. I think it is a bug. Analysis reports of each same code file should be equivalent.

Please refer to the MCVE project.

@LynnBroe
Copy link
Author

LynnBroe commented Apr 6, 2023

HE_USE_OF_UNHASHABLE_CLASS has a similar problem

gtoison added a commit to gtoison/spotbugs that referenced this issue Aug 27, 2023
HE_SIGNATURE_DECLARES_HASHING_OF_UNHASHABLE_CLASS is reported for TestA,
TestC and TestD, not for TestB
hazendaz pushed a commit that referenced this issue Aug 28, 2023
…me classes (#2538)

* test: issue #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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant