groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <eric.mil...@thomsonreuters.com>
Subject Groovy 2.5.0-beta-3 feedback
Date Mon, 26 Feb 2018 15:20:34 GMT
A couple notes on Groovy 2.5b3:

1) The groovy-2.5.0-beta-3-sources.jar on Maven Central has a lot of duplicate source entries;
at least under the groovy packages.

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


    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;
        }
    }

Eric Milles
Lead Software Engineer
Thomson Reuters
Email: eric.milles@thomsonreuters.com
Phone: 651-848-7040


Mime
View raw message