groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8485) PropertyHandler support producing errors when supplied class loader is not in loader chain of PropertyLoder.class
Date Sat, 24 Mar 2018 17:13:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8485?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16412695#comment-16412695
] 

Eric Milles commented on GROOVY-8485:
-------------------------------------

I have a similar problem in {{ASTTransformCollectorCodeVisitor}}'s {{verifyClass}} and {{verifyCompilePhase}}
methods, when I roll back some parent {{ClassLoader}} chaining.

For some additional background, an Eclipse project has its own classpath defined by its config.
 Greclipse creates a {{URLClassLoader}} for this config and the {{GroovyClassLoader}} reference
on {{org.codehaus.groovy.ast.CompileUnit}} is set to a new GCL with the URL CL as its parent.
 There is some code to set a parent CL of the URL CL to one that has reference to the classpath
of the compiler (aka Eclipse).

I'm trying to break this last link because it is causing problems when the compiler uses Groovy
2.5 internally and is compiling a project that has Groovy 2.4 on compile/runtime classpath.

It seems Groovy Core assumes that the compiler's classpath and the compilation target are
one in the same, because there are direct class literals used to test assignability and to
look up annotations in AST transforms (which by definition have a separate "transforms loader").
 Maybe I still have some wires crossed in Eclipse with respect to the transforms loader...

> PropertyHandler support producing errors when supplied class loader is not in loader
chain of PropertyLoder.class
> -----------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-8485
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8485
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>            Priority: Major
>
> I'm having a little trouble with the new PropertyHandler stuff that supports @Immutable.
 The error "The propertyHandler class 'groovy.transform.options.ImmutablePropertyHandler'
on @MapConstructor  is not a propertyHandler" is showing anywhere @Immutable is applied. 
I think the ClassLoader used to load PropertyHandler was different from the one passed as
"loader" to the method below.  And so the isAssignableFrom check fails.  When I edit (see
below) to use the same class loader used for PropertyHandler, the check and typecast succeed.
>  
>  {code:java}
>     public static PropertyHandler createPropertyHandler(AbstractASTTransformation xform,
GroovyClassLoader loader, ClassNode cNode) {
>         List<AnnotationNode> annotations = cNode.getAnnotations(PROPERTY_OPTIONS_TYPE);
>         AnnotationNode anno = annotations.isEmpty() ? null : annotations.get(0);
>         if (anno == null) return new groovy.transform.options.DefaultPropertyHandler();
>  
>         ClassNode handlerClass = xform.getMemberClassValue(anno, "propertyHandler", ClassHelper.make(groovy.transform.options.DefaultPropertyHandler.class));
>  
>         if (handlerClass == null) {
>             xform.addError("Couldn't determine propertyHandler class", anno);
>             return null;
>         }
>  
>         String className = handlerClass.getName();
>         try {
>             // GRECLIPSE edit
>             //Object instance = loader.loadClass(className).newInstance();
>             Object instance = PropertyHandler.class.getClassLoader().loadClass(className).newInstance();
>             // GRECLIPSE end
>             if (instance == null) {
>                 xform.addError("Can't load propertyHandler '" + className + "'", anno);
>                 return null;
>             }
>             if (!PropertyHandler.class.isAssignableFrom(instance.getClass())) {
>                 xform.addError("The propertyHandler class '" + handlerClass.getName()
+ "' on " + xform.getAnnotationName() + " is not a propertyHandler", anno);
>                 return null;
>             }
>  
>             return (PropertyHandler) instance;
>         } catch (Exception e) {
>             xform.addError("Can't load propertyHandler '" + className + "' " + e, anno);
>             return null;
>         }
>     }
>  {code}
> Please note this is from within Eclipse IDE support.  So the GroovyClassLoader has a
different origin than the command-line tools provide.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message