Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8337622

IllegalArgumentException in java.lang.reflect.Field.get

XMLWordPrintable

    • b11

        I am seeing errors like the following testing JDK 23 that do not occur with JDK 22.

        ```
        Caused by: java.lang.IllegalArgumentException: Can not get final java.lang.Class field java.lang.Class.componentType on java.lang.Class
        at java.base/jdk.internal.reflect.MethodHandleFieldAccessorImpl.newGetIllegalArgumentException(MethodHandleFieldAccessorImpl.java:86)
        at java.base/jdk.internal.reflect.MethodHandleObjectFieldAccessorImpl.get(MethodHandleObjectFieldAccessorImpl.java:61)
        at java.base/java.lang.reflect.Field.get(Field.java:444)
        ```

        The symptoms look similar to https://bugs.openjdk.org/browse/JDK-8301663 which was fixed in JDK 20, but testing the repro from that bug shows a regression between JDK 22 and JDK 23:

        import java.lang.reflect.Field;
        public class C {

            public static void main(String[] args) throws Exception {
                int count = 0;
                for (int i = 0; i < 100_000; ++i) {
                    try {
                        Field f = Class.class.getDeclaredField("componentType");
                        f.setAccessible(true);
                        Object val = f.get(Runnable.class);
                    } catch (IllegalArgumentException e) {
                        count += 1;
                    }
                }
                System.out.println(count);
            }
        }

        java -fullversion
        openjdk full version "22.0.2+9-70"
        java --add-opens java.base/java.lang=ALL-UNNAMED C
        0

        java -fullversion
        openjdk full version "23-ea+34-2361"
        java --add-opens java.base/java.lang=ALL-UNNAMED C
        18499

              coleenp Coleen Phillimore
              cushon Liam Miller-Cushon
              Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

                Created:
                Updated:
                Resolved: