Copilot commented on code in PR #1814:
URL: https://github.com/apache/commons-lang/pull/1814#discussion_r4231994749
##########
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:
`Thread.currentThread().getContextClassLoader()` can be `null` under some
runners/environments, which would cause `Proxy.newProxyInstance` to throw.
Using a stable loader like `NestAnnotation.class.getClassLoader()` /
`TestAnnotation.class.getClassLoader()` (or
`AnnotationUtilsTest.class.getClassLoader()`) makes the test more robust across
different execution contexts.
##########
src/test/java/org/apache/commons/lang3/AnnotationUtilsTest.java:
##########
@@ -470,6 +470,33 @@ void testHashCode() {
});
}
+ @Test
+ void testHashCodeOfNestedAnnotationArray() {
+ assertTimeoutPreemptively(Duration.ofSeconds(666L), () -> {
Review Comment:
The timeout value (666 seconds) is unusually large for a unit test and
reduces the value of `assertTimeoutPreemptively` as a guard against hangs.
Consider using a smaller, conventional bound (e.g., a few seconds) or a shared
constant used elsewhere in the test suite to keep timeouts consistent and
meaningful.
##########
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:
`Thread.currentThread().getContextClassLoader()` can be `null` under some
runners/environments, which would cause `Proxy.newProxyInstance` to throw.
Using a stable loader like `NestAnnotation.class.getClassLoader()` /
`TestAnnotation.class.getClassLoader()` (or
`AnnotationUtilsTest.class.getClassLoader()`) makes the test more robust across
different execution contexts.
--
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]