-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
19
-
None
-
x86_64
-
linux
Annotation#toString() seems to use "." before the name of nested classes, while it used to use "$" in JDK 18 and earlier.
I'm aware that the javadoc of Annotation#toString() does specify that the representation is implementation-dependent. However, it seems inconsistent to use a different syntax than Class#getName() to represent nested classes, so I was wondering if this was an unintended regression?
Strangely, this regression seems to have been detected in https://bugs.openjdk.java.net/browse/JDK-8281674, but the resolution consisted in simply changing the expectations in the failing test.
You can find a reproducer here: https://github.com/yrodiere/jdk-playground/tree/annotation-tostring
Just run mvn clean install and see how it fails on JDK19, but succeeds on JDK 18 and earlier.
The test looks like this:
```java
public class MyTest {
@Test
void test() throws NoSuchFieldException {
Field myField = MyAnnotatedClass.class.getDeclaredField( "myField" );
MyAnnotation myAnnotation = myField.getAnnotation( MyAnnotation.class );
assertEquals( "@org.hibernate.jdk.playground.MyTest$MyAnnotation(myAttribute=\"foo\")", myAnnotation.toString() );
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MyAnnotation {
String myAttribute();
}
public static class MyAnnotatedClass {
@MyAnnotation(myAttribute = "foo")
String myField;
}
}
```
In JDK 18 and earlier, the test would pass.
In JDK 19-ea+10, it fails:
```
[ERROR] org.hibernate.jdk.playground.MyTest.test Time elapsed: 0.018 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <@org.hibernate.jdk.playground.MyTest$MyAnnotation(myAttribute="foo")> but was: <@org.hibernate.jdk.playground.MyTest.MyAnnotation(myAttribute="foo")>
at org.hibernate.jdk.playground.MyTest.test(MyTest.java:19)
```
I'm aware that the javadoc of Annotation#toString() does specify that the representation is implementation-dependent. However, it seems inconsistent to use a different syntax than Class#getName() to represent nested classes, so I was wondering if this was an unintended regression?
Strangely, this regression seems to have been detected in https://bugs.openjdk.java.net/browse/JDK-8281674, but the resolution consisted in simply changing the expectations in the failing test.
You can find a reproducer here: https://github.com/yrodiere/jdk-playground/tree/annotation-tostring
Just run mvn clean install and see how it fails on JDK19, but succeeds on JDK 18 and earlier.
The test looks like this:
```java
public class MyTest {
@Test
void test() throws NoSuchFieldException {
Field myField = MyAnnotatedClass.class.getDeclaredField( "myField" );
MyAnnotation myAnnotation = myField.getAnnotation( MyAnnotation.class );
assertEquals( "@org.hibernate.jdk.playground.MyTest$MyAnnotation(myAttribute=\"foo\")", myAnnotation.toString() );
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MyAnnotation {
String myAttribute();
}
public static class MyAnnotatedClass {
@MyAnnotation(myAttribute = "foo")
String myField;
}
}
```
In JDK 18 and earlier, the test would pass.
In JDK 19-ea+10, it fails:
```
[ERROR] org.hibernate.jdk.playground.MyTest.test Time elapsed: 0.018 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <@org.hibernate.jdk.playground.MyTest$MyAnnotation(myAttribute="foo")> but was: <@org.hibernate.jdk.playground.MyTest.MyAnnotation(myAttribute="foo")>
at org.hibernate.jdk.playground.MyTest.test(MyTest.java:19)
```