-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
9
A DESCRIPTION OF THE REQUEST :
If the compiler is (optionally) checking hashing in a given project/module/package, each class therein that is passed to code that contains (anywhere) a call to hashCode must have an explicit, non-inherited implementation of both equals() and hashCode() OR the explicit annotation @InheritHashEquals. Under this system, nobody can accidentally put un-hashable objects into HashMaps or HashSets or indeed any code that relies on hashing. The compiler can immediately warn the user instead of absorbing hours of their time searching for subtle collection bugs. The idea may need some work, but it's a nasty problem that even after 20+ years still needs to be addressed if at all possible.
JUSTIFICATION :
Just spent 3 hours this morning debugging a problem due to a missing but completely trivial hashCode/equals implementation. Ugh.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compiler should (optionally) check hash/equals and warn.
ACTUAL -
Subtle collection failures.
If the compiler is (optionally) checking hashing in a given project/module/package, each class therein that is passed to code that contains (anywhere) a call to hashCode must have an explicit, non-inherited implementation of both equals() and hashCode() OR the explicit annotation @InheritHashEquals. Under this system, nobody can accidentally put un-hashable objects into HashMaps or HashSets or indeed any code that relies on hashing. The compiler can immediately warn the user instead of absorbing hours of their time searching for subtle collection bugs. The idea may need some work, but it's a nasty problem that even after 20+ years still needs to be addressed if at all possible.
JUSTIFICATION :
Just spent 3 hours this morning debugging a problem due to a missing but completely trivial hashCode/equals implementation. Ugh.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compiler should (optionally) check hash/equals and warn.
ACTUAL -
Subtle collection failures.
- relates to
-
JDK-8009138 javac, equals-hashCode warning tuning
- Closed
-
JDK-6563143 javac should issue a warning for overriding equals without hashCode
- Closed
-
JDK-8008436 javac should not issue a warning for overriding equals without hasCode if hashCode has been overriden by a superclass
- Closed