Copilot commented on code in PR #1807:
URL: https://github.com/apache/commons-lang/pull/1807#discussion_r4177245397
##########
src/main/java/org/apache/commons/lang3/reflect/TypeUtils.java:
##########
@@ -236,7 +236,9 @@ private static final class WildcardTypeImpl implements
WildcardType {
* @param lowerBounds of this type.
*/
private WildcardTypeImpl(final Type[] upperBounds, final Type[]
lowerBounds) {
- this.upperBounds = upperBounds != null ? upperBounds.clone() :
ArrayUtils.EMPTY_TYPE_ARRAY;
+ // A wildcard with no explicit upper bound has an implicit upper
bound of Object, per
+ // WildcardType.getUpperBounds(); returning an empty array breaks
equals() with a JDK wildcard.
+ this.upperBounds = ArrayUtils.isNotEmpty(upperBounds) ?
upperBounds.clone() : new Type[] {Object.class};
Review Comment:
This makes the constructed wildcard equal to the JDK wildcard in both
directions, but `WildcardTypeImpl.hashCode()` still uses its custom shift/OR
formula while the JDK hashes the upper and lower bound arrays with XOR.
Consequently, `jdk.equals(built)` is now true while their hash codes differ,
violating the `equals`/`hashCode` contract (the new test only compares against
another `WildcardTypeImpl`). Please align `hashCode()` with the JDK algorithm
and assert `jdk.hashCode() == built.hashCode()`.
--
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]