Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6517779

javax.lang.model.util.Elements.getConstantExpression() doesn't throw any exception

XMLWordPrintable

        Elements.getConstantExpression() doesn't throw any exception when argument is not a primitive value or string while the spec states exception throwing.

        You may reproduce it using following code:
        ===
        import javax.annotation.processing.AbstractProcessor;
        import javax.annotation.processing.RoundEnvironment;
        import javax.lang.model.element.TypeElement;
        import javax.lang.model.SourceVersion;
        import java.util.Set;
        import javax.annotation.processing.SupportedAnnotationTypes;
        import javax.annotation.processing.SupportedSourceVersion;

        @SupportedSourceVersion(SourceVersion.RELEASE_6)
        @SupportedAnnotationTypes("*")
        public class Proc extends AbstractProcessor {
           public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
               if(roundEnv.processingOver()) {
                   System.out.println("object: " + processingEnv.getElementUtils().getConstantExpression(new Object()));
               }
               return true;
           }
        }
        ===

        The result is like this:
        # javac -processor tmp.Proc java.lang.Object
        object: java.lang.Object@ab853b
        Failed test:
        api/javax_lang/model/util/Elements/index.html#GetConstantExpression0002

              darcy Joe Darcy
              ydanilev Yury Danilevich (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: