Uploaded image for project: 'Apache Freemarker'
  1. Apache Freemarker
  2. FREEMARKER-216

IllegalAccessException in Java 17

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.3.32
    • 2.3.33
    • engine
    • None

    Description

      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?

      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
      
      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)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            chrylis Christopher Smith
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: