alhudz opened a new pull request, #1814: URL: https://github.com/apache/commons-lang/pull/1814
`Repro:` take any annotation with a nested-annotation array member (`NestAnnotation[] nests()` on `AnnotationUtilsTest.TestAnnotation`) and build an equivalent instance whose `nests()` elements are an implementation that does not follow `Annotation#hashCode()` — a hand-written class, or a `Proxy` like the one in `testGeneratedAnnotationEquivalentToRealAnnotation`. `AnnotationUtils.equals(real, generated)` is `true` both ways and `AnnotationUtils.toString` agrees, but `AnnotationUtils.hashCode(real) != AnnotationUtils.hashCode(generated)`. `Cause:` `arrayMemberHash` has no `componentType.isAnnotation()` branch, so an annotation-typed array member falls through to `Arrays.hashCode((Object[]) o)` and each element is hashed with its *own* `hashCode()`. Its sibling `arrayMemberEquals`, directly above it, does special-case that component type and recurses through `annotationArrayMemberEquals`, and `hashMember` already recurses for a *single* nested annotation — so only the array form trusts the member's own implementation, which is exactly what the class Javadoc says not to do. `Fix:` give `arrayMemberHash` the branch its sibling already has, delegating to `annotationArrayMemberHash`, which keeps the element order and seeding of `Arrays.hashCode(Object[])` but hashes each element with `AnnotationUtils.hashCode`. Real annotations hash to the same value as before, since a conforming element's `hashCode()` already equals `AnnotationUtils.hashCode(element)`; `testHashCode` covers that. `arrayMemberHash` is the only place in the library that hashes an annotation-typed array, so this is the single site. Added `AnnotationUtilsTest.testHashCodeOfNestedAnnotationArray`, which fails before the change (`expected: <600724993> but was: <506742513>`) and passes after. Full `mvn` default goal is green locally on Java 21. - [x] Read the [contribution guidelines](https://github.com/apache/commons-lang/blob/master/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's Claude) was used to help spot the missing branch, write the patch and the regression test, and draft this description; I reviewed and verified all of it against the build. - [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]
