[
https://issues.apache.org/jira/browse/FREEMARKER-216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17822851#comment-17822851
]
Dániel Dékány commented on FREEMARKER-216:
------------------------------------------
Fixed in 2.3-gae and 2.3 branches. The reason of this error is "JEP 396:
Strongly Encapsulate JDK Internals by Default", where now you are not allowed
to call public methods on public methods, if they are JDK internal. Better
said, if the target class is in a module that doesn't export the containing
package. Now we check if we have a such issue, and look for a similar method
that's in a class that is in an accessible package.
> IllegalAccessException in Java 17
> ---------------------------------
>
> Key: FREEMARKER-216
> URL: https://issues.apache.org/jira/browse/FREEMARKER-216
> Project: Apache Freemarker
> Issue Type: Bug
> Components: engine
> Affects Versions: 2.3.32
> Reporter: Christopher Smith
> Priority: Critical
>
> I am using Freemarker in an annotation processor to generate code. I supply
> an instance of {{javax.lang.model.element.TypeElement}}, which implements
> {{QualifiedNameable}}, to the template model and use
> {{element.qualifiedName}} as a template variable.
> My code works fine under Java 11, but after updating the compiler to Java 17
> (even with Java 11 compliance settings), I am receiving an
> {{IllegalAccessException}}.
> There seems to be a severely deficient implementation in the encapsulation of
> Java internals that does not make methods that implement an interface
> accessible, but perhaps it's possible to get the {{Method}} handles for the
> property accessors on interfaces? I see that
> {{ClassIntrospector#discoverAccessibleMethods}} tries to do this, but perhaps
> it's not taking into account JPMS?
> {code}
> Caused by: java.lang.IllegalAccessException: class
> freemarker.ext.beans.BeansWrapper cannot access class
> com.sun.tools.javac.code.Symbol$ClassSymbol (in module jdk.compiler) because
> module jdk.compiler does not export com.sun.tools.javac.code to unnamed
> module @43c3d622
> at
> java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
> at
> java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
> at java.base/java.lang.reflect.Method.invoke(Method.java:560)
> at
> freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1553)
> at
> freemarker.ext.beans.BeanModel.invokeThroughDescriptor(BeanModel.java:233)
> at freemarker.ext.beans.BeanModel.get(BeanModel.java:152)
> ... 129 more
> {code}
> {code}
> FreeMarker template error:An error has occurred when reading existing
> sub-variable "qualifiedName"; see cause exception! The type of the containing
> value was: extended_hash+string (com.sun.tools.javac.code.Symbol$ClassSymbol
> wrapped into f.e.b.StringModel)
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)