src/share/classes/sun/reflect/annotation/TypeAnnotation.java

Print this page
rev 8830 : 8023278: Reflection API methods do not throw AnnotationFormatError in case of malformed Runtime[In]VisibleTypeAnnotations attribute
Reviewed-by: duke

*** 145,191 **** } public static final LocationInfo BASE_LOCATION = new LocationInfo(); public static LocationInfo parseLocationInfo(ByteBuffer buf) { ! int depth = buf.get(); if (depth == 0) return BASE_LOCATION; Location[] locations = new Location[depth]; for (int i = 0; i < depth; i++) { byte tag = buf.get(); ! byte index = buf.get(); if (!(tag == 0 || tag == 1 | tag == 2 || tag == 3)) throw new AnnotationFormatError("Bad Location encoding in Type Annotation"); if (tag != 3 && index != 0) throw new AnnotationFormatError("Bad Location encoding in Type Annotation"); locations[i] = new Location(tag, index); } return new LocationInfo(depth, locations); } public LocationInfo pushArray() { ! return pushLocation((byte)0, (byte)0); } public LocationInfo pushInner() { ! return pushLocation((byte)1, (byte)0); } public LocationInfo pushWildcard() { ! return pushLocation((byte) 2, (byte) 0); } ! public LocationInfo pushTypeArg(byte index) { return pushLocation((byte) 3, index); } ! public LocationInfo pushLocation(byte tag, byte index) { int newDepth = this.depth + 1; Location[] res = new Location[newDepth]; System.arraycopy(this.locations, 0, res, 0, depth); ! res[newDepth - 1] = new Location(tag, index); return new LocationInfo(newDepth, res); } public TypeAnnotation[] filter(TypeAnnotation[] ta) { ArrayList<TypeAnnotation> l = new ArrayList<>(ta.length); --- 145,191 ---- } public static final LocationInfo BASE_LOCATION = new LocationInfo(); public static LocationInfo parseLocationInfo(ByteBuffer buf) { ! int depth = buf.get() & 0xFF; if (depth == 0) return BASE_LOCATION; Location[] locations = new Location[depth]; for (int i = 0; i < depth; i++) { byte tag = buf.get(); ! short index = (short)(buf.get() & 0xFF); if (!(tag == 0 || tag == 1 | tag == 2 || tag == 3)) throw new AnnotationFormatError("Bad Location encoding in Type Annotation"); if (tag != 3 && index != 0) throw new AnnotationFormatError("Bad Location encoding in Type Annotation"); locations[i] = new Location(tag, index); } return new LocationInfo(depth, locations); } public LocationInfo pushArray() { ! return pushLocation((byte)0, (short)0); } public LocationInfo pushInner() { ! return pushLocation((byte)1, (short)0); } public LocationInfo pushWildcard() { ! return pushLocation((byte) 2, (short) 0); } ! public LocationInfo pushTypeArg(short index) { return pushLocation((byte) 3, index); } ! public LocationInfo pushLocation(byte tag, short index) { int newDepth = this.depth + 1; Location[] res = new Location[newDepth]; System.arraycopy(this.locations, 0, res, 0, depth); ! res[newDepth - 1] = new Location(tag, (short)(index & 0xFF)); return new LocationInfo(newDepth, res); } public TypeAnnotation[] filter(TypeAnnotation[] ta) { ArrayList<TypeAnnotation> l = new ArrayList<>(ta.length);
*** 205,221 **** return true; } public static final class Location { public final byte tag; ! public final byte index; boolean isSameLocation(Location other) { return tag == other.tag && index == other.index; } ! public Location(byte tag, byte index) { this.tag = tag; this.index = index; } } } --- 205,221 ---- return true; } public static final class Location { public final byte tag; ! public final short index; boolean isSameLocation(Location other) { return tag == other.tag && index == other.index; } ! public Location(byte tag, short index) { this.tag = tag; this.index = index; } } }