changeset 2084:71adceaa8fa8

Fix problem with unsigned bytes and conversion to int. Improve formatting.
author wmdietl
date Fri, 18 Jan 2013 13:10:07 -0800
parents b7593d260c12
children 4d6c707bfbaf
files src/share/classes/com/sun/tools/classfile/TypeAnnotation.java src/share/classes/com/sun/tools/javac/code/TargetType.java src/share/classes/com/sun/tools/javac/jvm/ClassReader.java
diffstat 3 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/classfile/TypeAnnotation.java	Fri Jan 18 13:08:27 2013 -0800
+++ b/src/share/classes/com/sun/tools/classfile/TypeAnnotation.java	Fri Jan 18 13:10:07 2013 -0800
@@ -78,7 +78,7 @@
         // Copied from ClassReader
         int tag = cr.readUnsignedByte(); // TargetType tag is a byte
         if (!TargetType.isValidTargetTypeValue(tag))
-            throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + tag);
+            throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag));
 
         TargetType type = TargetType.fromTargetTypeValue(tag);
 
@@ -600,7 +600,7 @@
         private TargetType(int targetTypeValue, boolean isLocal) {
             if (targetTypeValue < 0
                     || targetTypeValue > 255)
-                    throw new AssertionError("Attribute type value needs to be an unsigned byte: " + targetTypeValue);
+                    throw new AssertionError("Attribute type value needs to be an unsigned byte: " + String.format("0x%02X", targetTypeValue));
             this.targetTypeValue = targetTypeValue;
             this.isLocal = isLocal;
         }
--- a/src/share/classes/com/sun/tools/javac/code/TargetType.java	Fri Jan 18 13:08:27 2013 -0800
+++ b/src/share/classes/com/sun/tools/javac/code/TargetType.java	Fri Jan 18 13:10:07 2013 -0800
@@ -118,7 +118,7 @@
     private TargetType(int targetTypeValue, boolean isLocal) {
         if (targetTypeValue < 0
                 || targetTypeValue > 255)
-                Assert.error("Attribute type value needs to be an unsigned byte: " + targetTypeValue);
+                Assert.error("Attribute type value needs to be an unsigned byte: " + String.format("0x%02X", targetTypeValue));
         this.targetTypeValue = targetTypeValue;
         this.isLocal = isLocal;
     }
--- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Jan 18 13:08:27 2013 -0800
+++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java	Fri Jan 18 13:10:07 2013 -0800
@@ -351,8 +351,8 @@
 
     /** Read a byte.
      */
-    byte nextByte() {
-        return buf[bp++];
+    int nextByte() {
+        return buf[bp++] & 0xFF;
     }
 
     /** Read an integer.
@@ -1462,7 +1462,7 @@
         int tag = nextByte(); // TargetType tag is a byte
 
         if (!TargetType.isValidTargetTypeValue(tag))
-            throw this.badClassFile("bad.type.annotation.value", "0x" + Integer.toHexString(tag));
+            throw this.badClassFile("bad.type.annotation.value", String.format("0x%02X", tag));
 
         TypeAnnotationPosition position = new TypeAnnotationPosition();
         TargetType type = TargetType.fromTargetTypeValue(tag);
@@ -1549,7 +1549,7 @@
             int len = nextByte();
             ListBuffer<Integer> loc = ListBuffer.lb();
             for (int i = 0; i < len * TypeAnnotationPosition.TypePathEntry.bytesPerEntry; ++i)
-                loc = loc.append((int)nextByte());
+                loc = loc.append(nextByte());
             position.location = TypeAnnotationPosition.getTypePathFromBinary(loc.toList());
         }