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

Cannot read fields of java.lang.reflect.Field class

XMLWordPrintable

    • b12
    • 12
    • x86_64
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10
      Java 12 early #27

      A DESCRIPTION OF THE PROBLEM :
      Calling Field.class.getDeclaredField("modifiers") throws an exception but it exists.
      It's usually used to update private static fields (like in tests in my case) like explained in http://java-performance.info/updating-final-and-static-final-fields/ : you mark the field accessible and you change its modifier value

      REGRESSION : Last worked in version 11.0.1

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Simply call Field.class.getDeclaredField("modifiers")

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      You have a Field object
      ACTUAL -
      An exception is thrown

      ---------- BEGIN SOURCE ----------
      import java.lang.reflect.Field;

      class Scratch {
          public static void main(String... args) throws Exception {
              Field modifiers = Field.class.getDeclaredField("modifiers");
              System.out.println("It's working: " + modifiers);
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


            alanb Alan Bateman
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: