alhudz opened a new pull request, #1807:
URL: https://github.com/apache/commons-lang/pull/1807
`TypeUtils.wildcardType().build()` (a wildcard with no explicit upper bound,
and likewise a `withLowerBounds`-only wildcard) stores an empty upper-bounds
array, so `getUpperBounds()` returns `[]`. The
`java.lang.reflect.WildcardType.getUpperBounds()` contract says the implicit
upper bound is `Object` when none is declared, which is what the JDK's own `?`
and this class's `getImplicitUpperBounds` both report. Because of the mismatch
`equals` is asymmetric across implementations: `built.equals(jdkWildcard)` is
`true` (our `equals` normalises the empty array to `Object`) while
`jdkWildcard.equals(built)` is `false` (the JDK compares the raw bounds
arrays), and `built.hashCode()` disagrees with `WILDCARD_ALL.hashCode()`
although the two are equal.
Default the stored upper bounds to `Object` in the `WildcardTypeImpl`
constructor so `getUpperBounds()`, `equals()` and `hashCode()` all line up with
the JDK. Keeping it in the constructor is what makes the three agree from one
place; explicitly bounded wildcards and `WILDCARD_ALL` are untouched, and
`toString()` still renders `?` because the formatter already treats an `Object`
upper bound as unbounded.
Repro:
WildcardType built = TypeUtils.wildcardType().build();
WildcardType jdk = /* the ? taken from a List<?> field via reflection
*/;
Expected: `built.getUpperBounds()` is `[Object.class]`; `jdk.equals(built)`
is `true`
Actual (before): `built.getUpperBounds()` is `[]`; `jdk.equals(built)` is
`false`
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [x] Read the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use
Artificial Intelligence (AI).
- [x] I used AI to create any part of, or all of, this pull request. Which
AI tool was used to create this pull request, and to what extent did it
contribute? AI tooling (Claude) helped locate the defect and draft the change,
the test and this description; I reviewed and verified everything and ran the
full `mvn` build locally.
- [x] Run a successful build using the default
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command
line by itself.
- [x] Write unit tests that match behavioral changes, where the tests fail
if the changes to the runtime are not applied. This may not always be possible,
but it is a best practice.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line
and body. Note that a maintainer may squash commits during the merge process.
--
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]