Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-9596

Cannot access protected field of Java superclass with --illegal-access=deny

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.4, 2.5.12
    • 5.0.0-alpha-1
    • bytecode
    • None
    • JDK 14
      Groovy 2.5.12 or 3.0.4

    Description

      When using the Java option --illegal-access=deny, a Groovy subclass that extends a Java superclass in the Java runtime (e.g., a class in the java.base module) cannot access a protected field in the parent class using this.fieldName.

      To reproduce this bug, use JDK 14 (or later) and run the following using either Groovy 2.5.12 or 3.0.4:

      $ groovyc Main.groovy MyFilterReader.groovy
      $ _JAVA_OPTIONS="--illegal-access=deny" groovy Main

      It works correctly without --illegal-access=deny. You can add -Dsun.reflect.debugModuleAccessChecks=access to get more detailed information about the illegal access exceptions that are being swallowed by Groovy.

      $ _JAVA_OPTIONS="--illegal-access=deny -Dsun.reflect.debugModuleAccessChecks=access" groovy Main

      WORKAROUND: change the following line in the Groovy subclass:

      line = ((BufferedReader)this.in).readLine();

      to:

      line = ((BufferedReader)super.in).readLine();

      Attachments

        1. Main.groovy
          0.3 kB
          Kevin Rushforth
        2. Main2.groovy
          0.0 kB
          Kevin Rushforth
        3. MyAWTEvent.groovy
          0.3 kB
          Kevin Rushforth
        4. MyFilterReader.groovy
          2 kB
          Kevin Rushforth

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kevinrushforth Kevin Rushforth
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: