[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-compiler-dev
Subject:    java.lang.UnsupportedOperationException with JDK9 and JDK10
From:       Petar Tahchiev <paranoiabla () gmail ! com>
Date:       2018-04-08 7:54:20
Message-ID: CAKnbemXm65Bs=9cVn8YQn1R=RdaV_4=5byr3SfJKMCiT=uJvHA () mail ! gmail ! com
[Download RAW message or body]

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


[Attachment #3 (text/html)]

<div dir="ltr"><div><div>Hello everyone,<br><br></div>I&#39;m posting my question \
here, because I&#39;m not sure if it is a bug, or perhaps just the default behavior \
changed in JDK9. <br><br></div>I have custom annotation processor which has the \
following method:<br><br>       protected &lt;T&gt; T \
getAnnotationMember(AnnotationMirror annotation, String member) {<br>               \
return processingEnv.getElementUtils().getElementValuesWithDefaults(annotation).entrySet().stream().filter(<br> \
e -&gt; Objects.equals(member, e.getKey().getSimpleName().toString())).map(element \
-&gt; {<br>                       @SuppressWarnings(&quot;unchecked&quot;)<br>        \
T value = (T) element.getValue().getValue();     // ---&gt;   EXCEPTION HAPPENS \
HERE!!!!! This is line 89<br>                       return value;<br>               \
}).findFirst().orElseThrow(<br>                                               () \
-&gt; new IllegalArgumentException(String.format(&quot;Member &#39;%s&#39; not found \
in mirror for annotation [%s]&quot;, member, annotation)));<br>       }<br \
clear="all"><div><div><div><br><br></div><div>it pretty much tries to find all \
classes with this annotation:<br><br>       @interface GeneratorFilter {<br>          \
/**<br>                 * Exclude code generator classes such that will not be \
applied by the processor.<br>                 *<br>                 * @return the \
generators to exclude.<br>                 */<br>               Class&lt;? extends \
CodeGenerator&gt;[] exclude() default {};<br><br>               /**<br>               \
* Include code generator classes even when not registered as a service.<br>           \
*<br>                 * @return the generators to include.<br>                 */<br> \
Class&lt;? extends CodeGenerator&gt;[] include() default {};<br><br>       \
}<br></div><br></div><div>and get the value of the exclude() method. However with \
JDK9 or JDK10 I get this exception:<br><br>Caused by: \
java.lang.UnsupportedOperationException<br>       at \
jdk.compiler/com.sun.tools.javac.code.Attribute.getValue(Attribute.java:58)<br>       \
at com.nemesis.platform.core.mixin.processor.AbstractMixInAnnotationProcessor.lambda$getAnnotationMember$2(AbstractMixInAnnotationProcessor.java:89)<br> \
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)<br> \
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)<br> \
at java.base/java.util.Spliterators$IteratorSpliterator.tryAdvance(Spliterators.java:1812)<br><br></div><div>1) \
At the time of evaluation with Java8:<br></div><div>- element = LinkedHashMap$Entry \
(&quot;exclude()&quot; -&gt; &quot;{}&quot;)<br></div><div>- element.getValue() = \
Attribute$Array ({})<br></div><div>- element.getValue().getValue() = List (size = \
0)<br><br></div><div>2) At the time of evaluation with \
Java9/Java10:<br></div><div><div>- element   = LinkedHashMap$Entry \
(&quot;exclude()&quot; -&gt; &quot;{}&quot;)<br></div><div>- element.getValue() = \
ClassReader$ArrayAttributeProxy ({})<br></div><div>- element.getValue().getValue() = \
UnsupportedOperationException<br><br></div><div></div><br></div><div>Is this a bug, \
or the behaviour changed? How can I access the value of exclude() method with JDK9 or \
JDK10?<br><br></div><div>Thank you.<br></div><div><br><br></div><div><div><br>-- \
<br><div class="gmail_signature"><div dir="ltr"><div>Regards, Petar!<br>Karlovo, \
Bulgaria.<br>---<br>Public PGP Key at: <a \
href="http://pgp.mit.edu:11371/pks/lookup?op=get&amp;search=0x19658550C3110611" \
target="_blank">http://pgp.mit.edu:11371/pks/lookup?op=get&amp;search=0x19658550C3110611</a><br>Key \
Fingerprint: A369 A7EE 61BC 93A3 CDFF   55A5 1965 8550 C311 0611</div></div></div> \
</div></div></div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic