sharanggupta opened a new pull request, #1812: URL: https://github.com/apache/commons-lang/pull/1812
Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated! Before you push a pull request, review this list: - [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? — Claude Code (Anthropic) assisted in drafting the code change, the regression tests and this description. The result was reviewed, the new tests were confirmed to fail on `master` and pass with the change, and the full default `mvn` build was run successfully before opening this PR. - [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. --- Fixes https://issues.apache.org/jira/browse/LANG-1836 ### What `TypeUtils.containsTypeVariables(Type)` ignored `ParameterizedType#getOwnerType()`, so `Outer<T>.Inner` was reported as containing no type variables, contradicting its Javadoc. `TypeUtils.unrollVariables(Map, Type)` never unrolled the owner, and when an owner was present it merged `getTypeArguments(p)` over the caller's map with `putAll`, which for `Outer<T>.Inner<T>` injects the identity entry `T -> T` and discards the caller's `T -> String`. ### How - `containsTypeVariables`: after the type arguments, also recurse into the owner type, unless it is a raw `Class` (e.g. `Map.class` owning `Map.Entry<String, Integer>`), because the `Class` branch returns true for any class that merely declares type parameters. - `unrollVariables`: unroll the type arguments directly against the caller's map (the `getTypeArguments(p)` merge is dropped: the actual type arguments are expressed in the enclosing scope's variables, which the caller's map is responsible for, not the raw type's own parameters), unroll a non-`Class` owner the same way, and rebuild with `parameterizeWithOwner(unrolledOwner, raw, args)`. - The `visited` guard from LANG-1700 is now released once a variable has been resolved, so a variable that occurs more than once in a type is unrolled everywhere (`Map<T, T>` previously became `Map<String, T>`); genuine cycles such as `T -> U -> T` are still cut. This was required for `Outer<T>.Inner<T>` → `Outer<String>.Inner<String>`. Happy to split it into its own ticket if preferred. Note: on current `master`, `Outer<T>.Inner<T>` no longer overflows the stack as the ticket describes (the LANG-1700 guard already stops that); it returns the type unchanged instead, which the new tests capture. ### Tests New `TypeUtilsTest` fixture `Outer<T>` with inner classes and regression tests that fail on `master`: - `containsTypeVariables`: `Outer<T>.Inner` → true, `Outer<T>.InnerU<Integer>` → true, `Outer<String>.Inner` → false, `Map.Entry<String, Integer>` → false. - `unrollVariables` with `{T -> String}`: `Outer<T>.Inner` → `Outer<String>.Inner`, `Outer<T>.InnerU<Integer>` → `Outer<String>.InnerU<Integer>`, `Outer<T>.InnerU<T>` → `Outer<String>.InnerU<String>`, `Map.Entry<T, Integer>` → `Map.Entry<String, Integer>` (raw owner unchanged), `Map<T, T>` → `Map<String, String>`. `mvn` (default goal) passes: 85,530 tests, 0 Checkstyle violations, PMD and SpotBugs clean, japicmp reports no incompatible changes. `changes.xml` entry added under 3.21.1. -- 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]
