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

javax.lang.model.util.Elements.getConstantExpression() with negative byte value fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 6
    • core-libs
    • None

        javax.lang.model.util.Elements.getConstantExpression() and negative argument value like 0xfd cause invalid string result "0xfd". While java.lang.Byte.decode("0xfd") and byte assignment like byte b = 0xfd cause to either exception or compiling error.

        You may reproduce it using following code:
        ===
        package tmp;

        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()) {
                   byte b = -3;
                   System.out.println("byte: " + processingEnv.getElementUtils().getConstantExpression(b));
               }
               return true;
           }
        }
        ===

        The result is like this:
        # javac -processor tmp.Proc java.lang.Object
        byte: 0xfd

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: