Mon, 28 Feb 2011 11:48:53 +0000
7015430: Incorrect thrown type determined for unchecked invocations
Summary: Thrown types do not get updated after 15.12.2.8, and do not get erased as per 15.12.2.6
Reviewed-by: jjg, dlsmith
jjg@46 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. |
jjg@46 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@46 | 4 | * |
jjg@46 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@46 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@554 | 7 | * published by the Free Software Foundation. Oracle designates this |
jjg@46 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
jjg@46 | 10 | * |
jjg@46 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@46 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@46 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@46 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@46 | 15 | * accompanied this code). |
jjg@46 | 16 | * |
jjg@46 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@46 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@46 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@46 | 20 | * |
ohair@554 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | * questions. |
jjg@46 | 24 | */ |
jjg@46 | 25 | |
jjg@46 | 26 | package com.sun.tools.classfile; |
jjg@46 | 27 | |
jjg@46 | 28 | import java.io.IOException; |
jjg@46 | 29 | |
jjg@46 | 30 | /** |
jjg@46 | 31 | * See JVMS3, section 4.8.16. |
jjg@46 | 32 | * |
jjg@581 | 33 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 34 | * If you write code that depends on this, you do so at your own risk. |
jjg@46 | 35 | * This code and its internal interfaces are subject to change or |
jjg@46 | 36 | * deletion without notice.</b> |
jjg@46 | 37 | */ |
jjg@46 | 38 | public class Annotation { |
jjg@46 | 39 | static class InvalidAnnotation extends AttributeException { |
jjg@198 | 40 | private static final long serialVersionUID = -4620480740735772708L; |
jjg@46 | 41 | InvalidAnnotation(String msg) { |
jjg@46 | 42 | super(msg); |
jjg@46 | 43 | } |
jjg@46 | 44 | } |
jjg@46 | 45 | |
jjg@46 | 46 | Annotation(ClassReader cr) throws IOException, InvalidAnnotation { |
jjg@46 | 47 | type_index = cr.readUnsignedShort(); |
jjg@46 | 48 | num_element_value_pairs = cr.readUnsignedShort(); |
jjg@46 | 49 | element_value_pairs = new element_value_pair[num_element_value_pairs]; |
jjg@46 | 50 | for (int i = 0; i < element_value_pairs.length; i++) |
jjg@46 | 51 | element_value_pairs[i] = new element_value_pair(cr); |
jjg@46 | 52 | } |
jjg@46 | 53 | |
jjg@46 | 54 | public Annotation(ConstantPool constant_pool, |
jjg@46 | 55 | int type_index, |
jjg@46 | 56 | element_value_pair[] element_value_pairs) { |
jjg@46 | 57 | this.type_index = type_index; |
jjg@46 | 58 | num_element_value_pairs = element_value_pairs.length; |
jjg@46 | 59 | this.element_value_pairs = element_value_pairs; |
jjg@46 | 60 | } |
jjg@46 | 61 | |
jjg@46 | 62 | public int length() { |
jjg@46 | 63 | int n = 2 /*type_index*/ + 2 /*num_element_value_pairs*/; |
jjg@46 | 64 | for (element_value_pair pair: element_value_pairs) |
jjg@46 | 65 | n += pair.length(); |
jjg@46 | 66 | return n; |
jjg@46 | 67 | } |
jjg@46 | 68 | |
jjg@46 | 69 | public final int type_index; |
jjg@46 | 70 | public final int num_element_value_pairs; |
jjg@46 | 71 | public final element_value_pair element_value_pairs[]; |
jjg@46 | 72 | |
jjg@46 | 73 | /** |
jjg@46 | 74 | * See JVMS3, section 4.8.16.1. |
jjg@46 | 75 | */ |
jjg@46 | 76 | public static abstract class element_value { |
jjg@46 | 77 | public static element_value read(ClassReader cr) |
jjg@46 | 78 | throws IOException, InvalidAnnotation { |
jjg@46 | 79 | int tag = cr.readUnsignedByte(); |
jjg@46 | 80 | switch (tag) { |
jjg@46 | 81 | case 'B': |
jjg@46 | 82 | case 'C': |
jjg@46 | 83 | case 'D': |
jjg@46 | 84 | case 'F': |
jjg@46 | 85 | case 'I': |
jjg@46 | 86 | case 'J': |
jjg@46 | 87 | case 'S': |
jjg@46 | 88 | case 'Z': |
jjg@46 | 89 | case 's': |
jjg@46 | 90 | return new Primitive_element_value(cr, tag); |
jjg@46 | 91 | |
jjg@46 | 92 | case 'e': |
jjg@46 | 93 | return new Enum_element_value(cr, tag); |
jjg@46 | 94 | |
jjg@46 | 95 | case 'c': |
jjg@46 | 96 | return new Class_element_value(cr, tag); |
jjg@46 | 97 | |
jjg@46 | 98 | case '@': |
jjg@46 | 99 | return new Annotation_element_value(cr, tag); |
jjg@46 | 100 | |
jjg@46 | 101 | case '[': |
jjg@46 | 102 | return new Array_element_value(cr, tag); |
jjg@46 | 103 | |
jjg@46 | 104 | default: |
jjg@46 | 105 | throw new InvalidAnnotation("unrecognized tag: " + tag); |
jjg@46 | 106 | } |
jjg@46 | 107 | } |
jjg@46 | 108 | |
jjg@46 | 109 | protected element_value(int tag) { |
jjg@46 | 110 | this.tag = tag; |
jjg@46 | 111 | } |
jjg@46 | 112 | |
jjg@46 | 113 | public abstract int length(); |
jjg@46 | 114 | |
jjg@46 | 115 | public abstract <R,P> R accept(Visitor<R,P> visitor, P p); |
jjg@46 | 116 | |
jjg@46 | 117 | public interface Visitor<R,P> { |
jjg@46 | 118 | R visitPrimitive(Primitive_element_value ev, P p); |
jjg@46 | 119 | R visitEnum(Enum_element_value ev, P p); |
jjg@46 | 120 | R visitClass(Class_element_value ev, P p); |
jjg@46 | 121 | R visitAnnotation(Annotation_element_value ev, P p); |
jjg@46 | 122 | R visitArray(Array_element_value ev, P p); |
jjg@46 | 123 | } |
jjg@46 | 124 | |
jjg@46 | 125 | public final int tag; |
jjg@46 | 126 | } |
jjg@46 | 127 | |
jjg@46 | 128 | public static class Primitive_element_value extends element_value { |
jjg@46 | 129 | Primitive_element_value(ClassReader cr, int tag) throws IOException { |
jjg@46 | 130 | super(tag); |
jjg@46 | 131 | const_value_index = cr.readUnsignedShort(); |
jjg@46 | 132 | } |
jjg@46 | 133 | |
jjg@46 | 134 | @Override |
jjg@46 | 135 | public int length() { |
jjg@46 | 136 | return 2; |
jjg@46 | 137 | } |
jjg@46 | 138 | |
jjg@46 | 139 | public <R,P> R accept(Visitor<R,P> visitor, P p) { |
jjg@46 | 140 | return visitor.visitPrimitive(this, p); |
jjg@46 | 141 | } |
jjg@46 | 142 | |
jjg@46 | 143 | public final int const_value_index; |
jjg@46 | 144 | |
jjg@46 | 145 | } |
jjg@46 | 146 | |
jjg@46 | 147 | public static class Enum_element_value extends element_value { |
jjg@46 | 148 | Enum_element_value(ClassReader cr, int tag) throws IOException { |
jjg@46 | 149 | super(tag); |
jjg@46 | 150 | type_name_index = cr.readUnsignedShort(); |
jjg@46 | 151 | const_name_index = cr.readUnsignedShort(); |
jjg@46 | 152 | } |
jjg@46 | 153 | |
jjg@46 | 154 | @Override |
jjg@46 | 155 | public int length() { |
jjg@46 | 156 | return 4; |
jjg@46 | 157 | } |
jjg@46 | 158 | |
jjg@46 | 159 | public <R,P> R accept(Visitor<R,P> visitor, P p) { |
jjg@46 | 160 | return visitor.visitEnum(this, p); |
jjg@46 | 161 | } |
jjg@46 | 162 | |
jjg@46 | 163 | public final int type_name_index; |
jjg@46 | 164 | public final int const_name_index; |
jjg@46 | 165 | } |
jjg@46 | 166 | |
jjg@46 | 167 | public static class Class_element_value extends element_value { |
jjg@46 | 168 | Class_element_value(ClassReader cr, int tag) throws IOException { |
jjg@46 | 169 | super(tag); |
jjg@46 | 170 | class_info_index = cr.readUnsignedShort(); |
jjg@46 | 171 | } |
jjg@46 | 172 | |
jjg@46 | 173 | @Override |
jjg@46 | 174 | public int length() { |
jjg@46 | 175 | return 2; |
jjg@46 | 176 | } |
jjg@46 | 177 | |
jjg@46 | 178 | public <R,P> R accept(Visitor<R,P> visitor, P p) { |
jjg@46 | 179 | return visitor.visitClass(this, p); |
jjg@46 | 180 | } |
jjg@46 | 181 | |
jjg@46 | 182 | public final int class_info_index; |
jjg@46 | 183 | } |
jjg@46 | 184 | |
jjg@46 | 185 | public static class Annotation_element_value extends element_value { |
jjg@46 | 186 | Annotation_element_value(ClassReader cr, int tag) |
jjg@46 | 187 | throws IOException, InvalidAnnotation { |
jjg@46 | 188 | super(tag); |
jjg@46 | 189 | annotation_value = new Annotation(cr); |
jjg@46 | 190 | } |
jjg@46 | 191 | |
jjg@46 | 192 | @Override |
jjg@46 | 193 | public int length() { |
jjg@46 | 194 | return annotation_value.length(); |
jjg@46 | 195 | } |
jjg@46 | 196 | |
jjg@46 | 197 | public <R,P> R accept(Visitor<R,P> visitor, P p) { |
jjg@46 | 198 | return visitor.visitAnnotation(this, p); |
jjg@46 | 199 | } |
jjg@46 | 200 | |
jjg@46 | 201 | public final Annotation annotation_value; |
jjg@46 | 202 | } |
jjg@46 | 203 | |
jjg@46 | 204 | public static class Array_element_value extends element_value { |
jjg@46 | 205 | Array_element_value(ClassReader cr, int tag) |
jjg@46 | 206 | throws IOException, InvalidAnnotation { |
jjg@46 | 207 | super(tag); |
jjg@46 | 208 | num_values = cr.readUnsignedShort(); |
jjg@46 | 209 | values = new element_value[num_values]; |
jjg@46 | 210 | for (int i = 0; i < values.length; i++) |
jjg@46 | 211 | values[i] = element_value.read(cr); |
jjg@46 | 212 | } |
jjg@46 | 213 | |
jjg@46 | 214 | @Override |
jjg@46 | 215 | public int length() { |
jjg@46 | 216 | int n = 2; |
jjg@46 | 217 | for (int i = 0; i < values.length; i++) |
jjg@46 | 218 | n += values[i].length(); |
jjg@46 | 219 | return n; |
jjg@46 | 220 | } |
jjg@46 | 221 | |
jjg@46 | 222 | public <R,P> R accept(Visitor<R,P> visitor, P p) { |
jjg@46 | 223 | return visitor.visitArray(this, p); |
jjg@46 | 224 | } |
jjg@46 | 225 | |
jjg@46 | 226 | public final int num_values; |
jjg@46 | 227 | public final element_value[] values; |
jjg@46 | 228 | } |
jjg@46 | 229 | |
jjg@46 | 230 | public static class element_value_pair { |
jjg@46 | 231 | element_value_pair(ClassReader cr) |
jjg@46 | 232 | throws IOException, InvalidAnnotation { |
jjg@46 | 233 | element_name_index = cr.readUnsignedShort(); |
jjg@46 | 234 | value = element_value.read(cr); |
jjg@46 | 235 | } |
jjg@46 | 236 | |
jjg@46 | 237 | public int length() { |
jjg@46 | 238 | return 2 + value.length(); |
jjg@46 | 239 | } |
jjg@46 | 240 | |
jjg@46 | 241 | public final int element_name_index; |
jjg@46 | 242 | public final element_value value; |
jjg@46 | 243 | } |
jjg@46 | 244 | } |