alhudz commented on code in PR #1814:
URL: https://github.com/apache/commons-lang/pull/1814#discussion_r4242513484
##########
src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java:
##########
@@ -470,6 +470,33 @@ void testHashCode() {
});
}
+ @Test
+ void testHashCodeOfNestedAnnotationArray() {
+ assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
+ final TestAnnotation real =
field1.getAnnotation(TestAnnotation.class);
+ // A nested annotation whose own hashCode() does not follow
Annotation#hashCode().
+ final InvocationHandler nestHandler = (proxy, method, args) -> {
+ if ("hashCode".equals(method.getName()) &&
method.getParameterTypes().length == 0) {
+ return Integer.valueOf(System.identityHashCode(proxy));
+ }
+ return method.invoke(real.nests()[0], args);
+ };
+ final NestAnnotation[] nests = { (NestAnnotation)
Proxy.newProxyInstance(
+ Thread.currentThread().getContextClassLoader(), new
Class[] { NestAnnotation.class }, nestHandler) };
Review Comment:
Done in 76b876c — this proxy now uses
`NestAnnotation.class.getClassLoader()` instead of the context class loader.
##########
src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java:
##########
@@ -470,6 +470,33 @@ void testHashCode() {
});
}
+ @Test
+ void testHashCodeOfNestedAnnotationArray() {
+ assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
+ final TestAnnotation real =
field1.getAnnotation(TestAnnotation.class);
+ // A nested annotation whose own hashCode() does not follow
Annotation#hashCode().
+ final InvocationHandler nestHandler = (proxy, method, args) -> {
+ if ("hashCode".equals(method.getName()) &&
method.getParameterTypes().length == 0) {
+ return Integer.valueOf(System.identityHashCode(proxy));
+ }
+ return method.invoke(real.nests()[0], args);
+ };
+ final NestAnnotation[] nests = { (NestAnnotation)
Proxy.newProxyInstance(
+ Thread.currentThread().getContextClassLoader(), new
Class[] { NestAnnotation.class }, nestHandler) };
+ final InvocationHandler testHandler = (proxy, method, args) -> {
+ if ("nests".equals(method.getName()) &&
method.getParameterTypes().length == 0) {
+ return nests;
+ }
+ return method.invoke(real, args);
+ };
+ final TestAnnotation generated = (TestAnnotation)
Proxy.newProxyInstance(
+ Thread.currentThread().getContextClassLoader(), new
Class[] { TestAnnotation.class }, testHandler);
Review Comment:
Same change here — switched to `TestAnnotation.class.getClassLoader()` in
76b876c.
##########
src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java:
##########
@@ -470,6 +470,33 @@ void testHashCode() {
});
}
+ @Test
+ void testHashCodeOfNestedAnnotationArray() {
+ assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
Review Comment:
Kept `666L` deliberately: it's the bound every other
`assertTimeoutPreemptively` in this file already uses, so a smaller value here
would be the inconsistent one. Can change it file-wide separately if wanted.
--
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]