Copilot commented on code in PR #1807:
URL: https://github.com/apache/commons-lang/pull/1807#discussion_r4178040058
##########
src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java:
##########
@@ -269,11 +271,8 @@ public Type[] getUpperBounds() {
*/
@Override
public int hashCode() {
- int result = 73 << 8;
- result |= Arrays.hashCode(upperBounds);
- result <<= 8;
- result |= Arrays.hashCode(lowerBounds);
- return result;
+ // Same algorithm as the JDK's WildcardType, so that equal
wildcards share a hash code.
+ return Arrays.hashCode(lowerBounds) ^ Arrays.hashCode(upperBounds);
Review Comment:
The new formula still violates `equals`/`hashCode` for builder inputs
already covered by `testUnboundedWildcardType`: `withLowerBounds((Type)
null).withUpperBounds().build()` equals `WILDCARD_ALL` because
`getImplicitLowerBounds` treats an empty array and `[null]` identically, but
their raw lower-bound array hashes are 31 and 1. Upper bounds have the same
risk because `equals` normalizes redundant bounds while this hashes them raw.
Hash the same canonical forms used by equality (while keeping an absent lower
bound as the JDK's empty array), and add a hash assertion to the existing test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]