groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (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 Thu, 01 Mar 2018 07:35:00 GMT

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

Paul King commented on GROOVY-8485:
-----------------------------------

Just to clarify (to confirm I understand your last comment), when you compile examples using
groovyc or say gradle, they work fine but not when compiling/running with Eclipse?

> 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