groovy
  1. groovy
  2. GROOVY-5140

ASTTransformationCustomizer uses wrong classloader to find transformer class from annotation

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8.4
    • Fix Version/s: 1.8.5, 2.0-beta-2
    • Component/s: Compiler
    • Labels:
      None
    • Number of attachments :
      0

      Description

      ASTTransformationCustomizer.

      In this method:

          private static Class<ASTTransformation> findASTTranformationClass(Class<? extends Annotation> anAnnotationClass) {
              final GroovyASTTransformationClass annotation = anAnnotationClass.getAnnotation(GroovyASTTransformationClass)
              if (annotation==null) throw new IllegalArgumentException("Provided class doesn't look like an AST @interface")
      
              Class[] classes = annotation.classes()
              String[] classesAsStrings = annotation.value()
              if (classes.length+classesAsStrings.length>1) {
                  throw new IllegalArgumentException("AST transformation customizer doesn't support AST transforms with multiple classes")
              }
              return classes?classes[0]:Class.forName(classesAsStrings[0])
          }
      

      Class.forName has no classloader, which means it using the loader associated with ASTTransformationCustomizer, but when I use it from inside STS that loader is associated with the Eclipse/STS infrastructure and the transform isn't on its classpath (since it is part of the compiled project, not the compiler infrastructure).

      It would seem more logical/correct if Class.forName here should use an explicit classloader and pass it the classloader from the annotation instead. After all, I think the annotation class should refer to the transformer class, so the annotation's classloader should be able to find the transform class.

      On the other hand, there doesn't seem to be a logical connection between ASTTransformationCustomizer and some random transform class attached to a random annotation that guarantees the class can be found by the ASTTransformationCustomizer's classloader.

        Activity

          People

          • Assignee:
            CÚdric Champeau
            Reporter:
            Kris De Volder
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: