JDK-7082069 : ParameterizedType does not define hashCode implementation
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 7
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86
  • Submitted: 2011-08-22
  • Updated: 2024-06-13
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
The API states:
Instances of classes that implement this interface must implement an equals() method that equates any two instances that share the same generic type declaration and have equal type parameters.

Indicating that custom implementation of this interface is allowed, but the documentation does not state how the hashCode() is calculated. Without this information users cannot reliably place their implementations of ParameterizedType with other implementations of ParameterizedType in a data structure like a HashMap.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An implementation of the hashCode:
The implementors of this interface must define hashCode to be the xor of the hashCode of the owner type (if not null), the raw type, and the result of Arrays.hashCode(actualParameterTypes) where actualParameterTypes is the array returned by actualParameterTypes() method.
ACTUAL -
The implementation of hashCode is missing

URL OF FAULTY DOCUMENTATION :
http://download.oracle.com/javase/7/docs/api/java/lang/reflect/ParameterizedType.html

Comments
All that actually needs to be done is to document the behavior of the "hashCode" methods in the current implementation, so other implementations can follow the specification. For the interface ParameterizedType, it already states how its "equals" method should behave. A paragraph stating how "hashCode" should behave (documenting the current implementation) would be sufficient to allow 3rd parties to create compatible implementations.
01-03-2020

All subtypes of java.lang.reflect.Type should be examined for their equals and hashCode behavior.
21-02-2013