You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Kevin Rushforth (Jira)" <ji...@apache.org> on 2021/05/15 14:21:00 UTC
[jira] [Commented] (GROOVY-9596) Cannot access protected field of
Java superclass with --illegal-access=deny
[ https://issues.apache.org/jira/browse/GROOVY-9596?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17345047#comment-17345047 ]
Kevin Rushforth commented on GROOVY-9596:
-----------------------------------------
With the recently-released gradle 7, which includes groovy 3.0.7, we can update our build to use JDK 16. I see that this bug is still present, so I ended up needing to implement the workaround I mentioned in the description (using `super.in` rather than `this.in`).
When more developers start using JDK 16 you may expect to receive more reports of problems like this. Note also that starting with JDK 17, it will no longer be possible to globally disable strong encapsulation. This may mean that some developers who are using that global switch as a workaround in JDK 16 will be stuck. It would be good to fix this and similar bugs in Groovy before JDK 17 is released.
> Cannot access protected field of Java superclass with --illegal-access=deny
> ---------------------------------------------------------------------------
>
> Key: GROOVY-9596
> URL: https://issues.apache.org/jira/browse/GROOVY-9596
> Project: Groovy
> Issue Type: Bug
> Components: bytecode
> Affects Versions: 3.0.4, 2.5.12
> Environment: JDK 14
> Groovy 2.5.12 or 3.0.4
> Reporter: Kevin Rushforth
> Priority: Major
> Attachments: Main.groovy, Main2.groovy, MyAWTEvent.groovy, MyFilterReader.groovy
>
>
> 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();
--
This message was sent by Atlassian Jira
(v8.3.4#803005)