java.lang.UnsupportedOperationException with JDK9 and JDK10

Petar Tahchiev paranoiabla at gmail.com
Sun Apr 8 07:54:20 UTC 2018


Hello everyone,

I'm posting my question here, because I'm not sure if it is a bug, or
perhaps just the default behavior changed in JDK9.

I have custom annotation processor which has the following method:

    protected <T> T getAnnotationMember(AnnotationMirror annotation, String
member) {
        return
processingEnv.getElementUtils().getElementValuesWithDefaults(annotation).entrySet().stream().filter(
                        e -> Objects.equals(member,
e.getKey().getSimpleName().toString())).map(element -> {
            @SuppressWarnings("unchecked")
            T value = (T) element.getValue().getValue();   // --->
EXCEPTION HAPPENS HERE!!!!! This is line 89
            return value;
        }).findFirst().orElseThrow(
                        () -> new
IllegalArgumentException(String.format("Member '%s' not found in mirror for
annotation [%s]", member, annotation)));
    }


it pretty much tries to find all classes with this annotation:

    @interface GeneratorFilter {
        /**
         * Exclude code generator classes such that will not be applied by
the processor.
         *
         * @return the generators to exclude.
         */
        Class<? extends CodeGenerator>[] exclude() default {};

        /**
         * Include code generator classes even when not registered as a
service.
         *
         * @return the generators to include.
         */
        Class<? extends CodeGenerator>[] include() default {};

    }

and get the value of the exclude() method. However with JDK9 or JDK10 I get
this exception:

Caused by: java.lang.UnsupportedOperationException
    at
jdk.compiler/com.sun.tools.javac.code.Attribute.getValue(Attribute.java:58)
    at
com.nemesis.platform.core.mixin.processor.AbstractMixInAnnotationProcessor.lambda$getAnnotationMember$2(AbstractMixInAnnotationProcessor.java:89)
    at
java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
    at
java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
    at
java.base/java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812)

1) At the time of evaluation with Java8:
- element = LinkedHashMap$Entry ("exclude()" -> "{}")
- element.getValue() = Attribute$Array ({})
- element.getValue().getValue() = List (size = 0)

2) At the time of evaluation with Java9/Java10:
- element  = LinkedHashMap$Entry ("exclude()" -> "{}")
- element.getValue() = ClassReader$ArrayAttributeProxy ({})
- element.getValue().getValue() = UnsupportedOperationException


Is this a bug, or the behaviour changed? How can I access the value of
exclude() method with JDK9 or JDK10?

Thank you.



-- 
Regards, Petar!
Karlovo, Bulgaria.
---
Public PGP Key at:
http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x19658550C3110611
Key Fingerprint: A369 A7EE 61BC 93A3 CDFF  55A5 1965 8550 C311 0611
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20180408/5124678e/attachment.html>


More information about the compiler-dev mailing list