Thu, 12 Jan 2012 15:28:34 +0000
7123100: javac fails with java.lang.StackOverflowError
Summary: Inference of under-constrained type-variables creates erroneous recursive wildcard types
Reviewed-by: jjg
jjg@309 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
jjg@309 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@309 | 4 | * |
jjg@309 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@309 | 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@309 | 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@309 | 10 | * |
jjg@309 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@309 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@309 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@309 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@309 | 15 | * accompanied this code). |
jjg@309 | 16 | * |
jjg@309 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@309 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@309 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@309 | 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@309 | 24 | */ |
jjg@309 | 25 | |
jjg@309 | 26 | package com.sun.tools.javac.code; |
jjg@309 | 27 | |
jjg@309 | 28 | import com.sun.tools.javac.util.*; |
jjg@309 | 29 | |
jjg@309 | 30 | /** A type annotation position. |
jjg@309 | 31 | * |
jjg@581 | 32 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 33 | * If you write code that depends on this, you do so at your own risk. |
jjg@309 | 34 | * This code and its internal interfaces are subject to change or |
jjg@309 | 35 | * deletion without notice.</b> |
jjg@309 | 36 | */ |
jjg@309 | 37 | public class TypeAnnotationPosition { |
jjg@309 | 38 | |
jjg@309 | 39 | public TargetType type = TargetType.UNKNOWN; |
jjg@309 | 40 | |
jjg@309 | 41 | // For generic/array types. |
jjg@309 | 42 | public List<Integer> location = List.nil(); |
jjg@309 | 43 | |
jjg@309 | 44 | // Tree position. |
jjg@309 | 45 | public int pos = -1; |
jjg@309 | 46 | |
jjg@309 | 47 | // For typecasts, type tests, new (and locals, as start_pc). |
jjg@310 | 48 | public boolean isValidOffset = false; |
jjg@309 | 49 | public int offset = -1; |
jjg@309 | 50 | |
jjg@309 | 51 | // For locals. arrays same length |
jjg@478 | 52 | public int[] lvarOffset = null; |
jjg@478 | 53 | public int[] lvarLength = null; |
jjg@478 | 54 | public int[] lvarIndex = null; |
jjg@309 | 55 | |
jjg@309 | 56 | // For type parameter bound |
jjg@478 | 57 | public int bound_index = Integer.MIN_VALUE; |
jjg@309 | 58 | |
jjg@309 | 59 | // For type parameter and method parameter |
jjg@478 | 60 | public int parameter_index = Integer.MIN_VALUE; |
jjg@309 | 61 | |
jjg@309 | 62 | // For class extends, implements, and throws classes |
jjg@478 | 63 | public int type_index = Integer.MIN_VALUE; |
jjg@309 | 64 | |
jjg@309 | 65 | // For wildcards |
jjg@309 | 66 | public TypeAnnotationPosition wildcard_position = null; |
jjg@309 | 67 | |
jjg@309 | 68 | @Override |
jjg@309 | 69 | public String toString() { |
jjg@309 | 70 | StringBuilder sb = new StringBuilder(); |
jjg@309 | 71 | sb.append('['); |
jjg@309 | 72 | sb.append(type); |
jjg@309 | 73 | |
jjg@309 | 74 | switch (type) { |
jjg@309 | 75 | // type case |
jjg@309 | 76 | case TYPECAST: |
jjg@309 | 77 | case TYPECAST_GENERIC_OR_ARRAY: |
jjg@309 | 78 | // object creation |
jjg@309 | 79 | case INSTANCEOF: |
jjg@309 | 80 | case INSTANCEOF_GENERIC_OR_ARRAY: |
jjg@309 | 81 | // new expression |
jjg@309 | 82 | case NEW: |
jjg@309 | 83 | case NEW_GENERIC_OR_ARRAY: |
jjg@309 | 84 | case NEW_TYPE_ARGUMENT: |
jjg@309 | 85 | case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY: |
jjg@309 | 86 | sb.append(", offset = "); |
jjg@309 | 87 | sb.append(offset); |
jjg@309 | 88 | break; |
jjg@309 | 89 | // local variable |
jjg@309 | 90 | case LOCAL_VARIABLE: |
jjg@309 | 91 | case LOCAL_VARIABLE_GENERIC_OR_ARRAY: |
jjg@309 | 92 | sb.append(", {"); |
jjg@309 | 93 | for (int i = 0; i < lvarOffset.length; ++i) { |
jjg@309 | 94 | if (i != 0) sb.append("; "); |
jjg@309 | 95 | sb.append(", start_pc = "); |
jjg@309 | 96 | sb.append(lvarOffset[i]); |
jjg@309 | 97 | sb.append(", length = "); |
jjg@309 | 98 | sb.append(lvarLength[i]); |
jjg@309 | 99 | sb.append(", index = "); |
jjg@309 | 100 | sb.append(lvarIndex[i]); |
jjg@309 | 101 | } |
jjg@309 | 102 | sb.append("}"); |
jjg@309 | 103 | break; |
jjg@309 | 104 | // method receiver |
jjg@309 | 105 | case METHOD_RECEIVER: |
jjg@309 | 106 | // Do nothing |
jjg@309 | 107 | break; |
jjg@309 | 108 | // type parameters |
jjg@309 | 109 | case CLASS_TYPE_PARAMETER: |
jjg@309 | 110 | case METHOD_TYPE_PARAMETER: |
jjg@309 | 111 | sb.append(", param_index = "); |
jjg@309 | 112 | sb.append(parameter_index); |
jjg@309 | 113 | break; |
jjg@309 | 114 | // type parameters bound |
jjg@309 | 115 | case CLASS_TYPE_PARAMETER_BOUND: |
jjg@309 | 116 | case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY: |
jjg@309 | 117 | case METHOD_TYPE_PARAMETER_BOUND: |
jjg@309 | 118 | case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY: |
jjg@309 | 119 | sb.append(", param_index = "); |
jjg@309 | 120 | sb.append(parameter_index); |
jjg@309 | 121 | sb.append(", bound_index = "); |
jjg@309 | 122 | sb.append(bound_index); |
jjg@309 | 123 | break; |
jjg@309 | 124 | // wildcard |
jjg@309 | 125 | case WILDCARD_BOUND: |
jjg@309 | 126 | case WILDCARD_BOUND_GENERIC_OR_ARRAY: |
jjg@309 | 127 | sb.append(", wild_card = "); |
jjg@309 | 128 | sb.append(wildcard_position); |
jjg@309 | 129 | break; |
jjg@309 | 130 | // Class extends and implements clauses |
jjg@309 | 131 | case CLASS_EXTENDS: |
jjg@309 | 132 | case CLASS_EXTENDS_GENERIC_OR_ARRAY: |
jjg@309 | 133 | sb.append(", type_index = "); |
jjg@309 | 134 | sb.append(type_index); |
jjg@309 | 135 | break; |
jjg@309 | 136 | // throws |
jjg@309 | 137 | case THROWS: |
jjg@309 | 138 | sb.append(", type_index = "); |
jjg@309 | 139 | sb.append(type_index); |
jjg@309 | 140 | break; |
jjg@309 | 141 | case CLASS_LITERAL: |
jjg@485 | 142 | case CLASS_LITERAL_GENERIC_OR_ARRAY: |
jjg@309 | 143 | sb.append(", offset = "); |
jjg@309 | 144 | sb.append(offset); |
jjg@309 | 145 | break; |
jjg@309 | 146 | // method parameter: not specified |
jjg@309 | 147 | case METHOD_PARAMETER_GENERIC_OR_ARRAY: |
jjg@309 | 148 | sb.append(", param_index = "); |
jjg@309 | 149 | sb.append(parameter_index); |
jjg@309 | 150 | break; |
jjg@309 | 151 | // method type argument: wasn't specified |
jjg@309 | 152 | case METHOD_TYPE_ARGUMENT: |
jjg@309 | 153 | case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY: |
jjg@309 | 154 | sb.append(", offset = "); |
jjg@309 | 155 | sb.append(offset); |
jjg@309 | 156 | sb.append(", type_index = "); |
jjg@309 | 157 | sb.append(type_index); |
jjg@309 | 158 | break; |
jjg@309 | 159 | // We don't need to worry abut these |
jjg@309 | 160 | case METHOD_RETURN_GENERIC_OR_ARRAY: |
jjg@309 | 161 | case FIELD_GENERIC_OR_ARRAY: |
jjg@309 | 162 | break; |
jjg@309 | 163 | case UNKNOWN: |
jjg@309 | 164 | break; |
jjg@309 | 165 | default: |
jjg@309 | 166 | // throw new AssertionError("unknown type: " + type); |
jjg@309 | 167 | } |
jjg@309 | 168 | |
jjg@309 | 169 | // Append location data for generics/arrays. |
jjg@309 | 170 | if (type.hasLocation()) { |
jjg@309 | 171 | sb.append(", location = ("); |
jjg@309 | 172 | sb.append(location); |
jjg@309 | 173 | sb.append(")"); |
jjg@309 | 174 | } |
jjg@309 | 175 | |
jjg@309 | 176 | sb.append(", pos = "); |
jjg@309 | 177 | sb.append(pos); |
jjg@309 | 178 | |
jjg@309 | 179 | sb.append(']'); |
jjg@309 | 180 | return sb.toString(); |
jjg@309 | 181 | } |
jjg@310 | 182 | |
jjg@310 | 183 | /** |
jjg@310 | 184 | * Indicates whether the target tree of the annotation has been optimized |
jjg@310 | 185 | * away from classfile or not. |
jjg@310 | 186 | * @return true if the target has not been optimized away |
jjg@310 | 187 | */ |
jjg@310 | 188 | public boolean emitToClassfile() { |
jjg@310 | 189 | if (type == TargetType.WILDCARD_BOUND |
jjg@310 | 190 | || type == TargetType.WILDCARD_BOUND_GENERIC_OR_ARRAY) |
jjg@310 | 191 | return wildcard_position.isValidOffset; |
jjg@310 | 192 | else |
jjg@310 | 193 | return !type.isLocal() || isValidOffset; |
jjg@310 | 194 | } |
jjg@309 | 195 | } |