You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2018/02/28 19:37:00 UTC

[jira] [Created] (GROOVY-8485) PropertyHandler support producing errors when supplied class loader is not in loader chain of PropertyLoder.class

Eric Milles created GROOVY-8485:
-----------------------------------

             Summary: 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


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)