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
duke@1 | 1 | /* |
ksrini@1052 | 2 | * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 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 |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 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. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javadoc; |
duke@1 | 27 | |
duke@1 | 28 | import com.sun.javadoc.*; |
duke@1 | 29 | |
duke@1 | 30 | /** |
duke@1 | 31 | * Documents a Serializable field defined by an ObjectStreamField. |
duke@1 | 32 | * <pre> |
duke@1 | 33 | * The class parses and stores the three serialField tag parameters: |
duke@1 | 34 | * |
duke@1 | 35 | * - field name |
duke@1 | 36 | * - field type name |
duke@1 | 37 | * (fully-qualified or visible from the current import context) |
duke@1 | 38 | * - description of the valid values for the field |
duke@1 | 39 | |
duke@1 | 40 | * </pre> |
duke@1 | 41 | * This tag is only allowed in the javadoc for the special member |
duke@1 | 42 | * serialPersistentFields. |
duke@1 | 43 | * |
duke@1 | 44 | * @author Joe Fialli |
duke@1 | 45 | * @author Neal Gafter |
duke@1 | 46 | * |
duke@1 | 47 | * @see java.io.ObjectStreamField |
duke@1 | 48 | */ |
duke@1 | 49 | class SerialFieldTagImpl |
duke@1 | 50 | extends TagImpl |
duke@1 | 51 | implements SerialFieldTag, Comparable<Object> |
duke@1 | 52 | { |
duke@1 | 53 | //### These could be final, except that the constructor |
duke@1 | 54 | //### does not set them directly. |
duke@1 | 55 | |
duke@1 | 56 | private String fieldName; // Required Argument 1 of serialField |
duke@1 | 57 | private String fieldType; // Required Argument 2 of serialField |
duke@1 | 58 | private String description; // Optional Remaining Arguments of serialField |
duke@1 | 59 | |
duke@1 | 60 | private ClassDoc containingClass; // Class containing serialPersistentField member |
duke@1 | 61 | private ClassDoc fieldTypeDoc; // ClassDocImpl of fieldType |
duke@1 | 62 | private FieldDocImpl matchingField; // FieldDocImpl with same name as fieldName |
duke@1 | 63 | |
duke@1 | 64 | /* Constructor. */ |
duke@1 | 65 | SerialFieldTagImpl(DocImpl holder, String name, String text) { |
duke@1 | 66 | super(holder, name, text); |
duke@1 | 67 | parseSerialFieldString(); |
duke@1 | 68 | if (holder instanceof MemberDoc) { |
duke@1 | 69 | containingClass = ((MemberDocImpl)holder).containingClass(); |
duke@1 | 70 | } |
duke@1 | 71 | } |
duke@1 | 72 | |
duke@1 | 73 | /* |
duke@1 | 74 | * The serialField tag is composed of three entities. |
duke@1 | 75 | * |
duke@1 | 76 | * serialField serializableFieldName serisliableFieldType |
duke@1 | 77 | * description of field. |
duke@1 | 78 | * |
duke@1 | 79 | * The fieldName and fieldType must be legal Java Identifiers. |
duke@1 | 80 | */ |
duke@1 | 81 | private void parseSerialFieldString() { |
duke@1 | 82 | int len = text.length(); |
ksrini@1052 | 83 | if (len == 0) { |
ksrini@1052 | 84 | return; |
ksrini@1052 | 85 | } |
duke@1 | 86 | |
duke@1 | 87 | // if no white space found |
duke@1 | 88 | /* Skip white space. */ |
duke@1 | 89 | int inx = 0; |
duke@1 | 90 | int cp; |
duke@1 | 91 | for (; inx < len; inx += Character.charCount(cp)) { |
duke@1 | 92 | cp = text.codePointAt(inx); |
duke@1 | 93 | if (!Character.isWhitespace(cp)) { |
duke@1 | 94 | break; |
duke@1 | 95 | } |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | /* find first word. */ |
duke@1 | 99 | int first = inx; |
duke@1 | 100 | int last = inx; |
duke@1 | 101 | cp = text.codePointAt(inx); |
duke@1 | 102 | if (! Character.isJavaIdentifierStart(cp)) { |
duke@1 | 103 | docenv().warning(holder, |
duke@1 | 104 | "tag.serialField.illegal_character", |
duke@1 | 105 | new String(Character.toChars(cp)), text); |
duke@1 | 106 | return; |
duke@1 | 107 | } |
duke@1 | 108 | |
duke@1 | 109 | for (inx += Character.charCount(cp); inx < len; inx += Character.charCount(cp)) { |
duke@1 | 110 | cp = text.codePointAt(inx); |
duke@1 | 111 | if (!Character.isJavaIdentifierPart(cp)) { |
duke@1 | 112 | break; |
duke@1 | 113 | } |
duke@1 | 114 | } |
duke@1 | 115 | |
duke@1 | 116 | if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) { |
duke@1 | 117 | docenv().warning(holder, |
duke@1 | 118 | "tag.serialField.illegal_character", |
duke@1 | 119 | new String(Character.toChars(cp)), text); |
duke@1 | 120 | return; |
duke@1 | 121 | } |
duke@1 | 122 | |
duke@1 | 123 | last = inx; |
duke@1 | 124 | fieldName = text.substring(first, last); |
duke@1 | 125 | |
duke@1 | 126 | /* Skip white space. */ |
duke@1 | 127 | for (; inx < len; inx += Character.charCount(cp)) { |
duke@1 | 128 | cp = text.codePointAt(inx); |
duke@1 | 129 | if (!Character.isWhitespace(cp)) { |
duke@1 | 130 | break; |
duke@1 | 131 | } |
duke@1 | 132 | } |
duke@1 | 133 | |
duke@1 | 134 | /* find second word. */ |
duke@1 | 135 | first = inx; |
duke@1 | 136 | last = inx; |
duke@1 | 137 | |
duke@1 | 138 | for (; inx < len; inx += Character.charCount(cp)) { |
duke@1 | 139 | cp = text.codePointAt(inx); |
duke@1 | 140 | if (Character.isWhitespace(cp)) { |
duke@1 | 141 | break; |
duke@1 | 142 | } |
duke@1 | 143 | } |
duke@1 | 144 | if (inx < len && ! Character.isWhitespace(cp = text.codePointAt(inx))) { |
duke@1 | 145 | docenv().warning(holder, |
duke@1 | 146 | "tag.serialField.illegal_character", |
duke@1 | 147 | new String(Character.toChars(cp)), text); |
duke@1 | 148 | return; |
duke@1 | 149 | } |
duke@1 | 150 | last = inx; |
duke@1 | 151 | fieldType = text.substring(first, last); |
duke@1 | 152 | |
duke@1 | 153 | /* Skip leading white space. Rest of string is description for serialField.*/ |
duke@1 | 154 | for (; inx < len; inx += Character.charCount(cp)) { |
duke@1 | 155 | cp = text.codePointAt(inx); |
duke@1 | 156 | if (!Character.isWhitespace(cp)) { |
duke@1 | 157 | break; |
duke@1 | 158 | } |
duke@1 | 159 | } |
duke@1 | 160 | description = text.substring(inx); |
duke@1 | 161 | } |
duke@1 | 162 | |
duke@1 | 163 | /** |
duke@1 | 164 | * return a key for sorting. |
duke@1 | 165 | */ |
duke@1 | 166 | String key() { |
duke@1 | 167 | return fieldName; |
duke@1 | 168 | } |
duke@1 | 169 | |
duke@1 | 170 | /* |
duke@1 | 171 | * Optional. Link this serialField tag to its corrsponding |
duke@1 | 172 | * field in the class. Note: there is no requirement that |
duke@1 | 173 | * there be a field in the class that matches serialField tag. |
duke@1 | 174 | */ |
duke@1 | 175 | void mapToFieldDocImpl(FieldDocImpl fd) { |
duke@1 | 176 | matchingField = fd; |
duke@1 | 177 | } |
duke@1 | 178 | |
duke@1 | 179 | /** |
duke@1 | 180 | * Return the serialziable field name. |
duke@1 | 181 | */ |
duke@1 | 182 | public String fieldName() { |
duke@1 | 183 | return fieldName; |
duke@1 | 184 | } |
duke@1 | 185 | |
duke@1 | 186 | /** |
duke@1 | 187 | * Return the field type string. |
duke@1 | 188 | */ |
duke@1 | 189 | public String fieldType() { |
duke@1 | 190 | return fieldType; |
duke@1 | 191 | } |
duke@1 | 192 | |
duke@1 | 193 | /** |
duke@1 | 194 | * Return the ClassDocImpl for field type. |
duke@1 | 195 | * |
duke@1 | 196 | * @returns null if no ClassDocImpl for field type is visible from |
duke@1 | 197 | * containingClass context. |
duke@1 | 198 | */ |
duke@1 | 199 | public ClassDoc fieldTypeDoc() { |
duke@1 | 200 | if (fieldTypeDoc == null && containingClass != null) { |
duke@1 | 201 | fieldTypeDoc = containingClass.findClass(fieldType); |
duke@1 | 202 | } |
duke@1 | 203 | return fieldTypeDoc; |
duke@1 | 204 | } |
duke@1 | 205 | |
duke@1 | 206 | /** |
duke@1 | 207 | * Return the corresponding FieldDocImpl for this SerialFieldTagImpl. |
duke@1 | 208 | * |
duke@1 | 209 | * @returns null if no matching FieldDocImpl. |
duke@1 | 210 | */ |
duke@1 | 211 | FieldDocImpl getMatchingField() { |
duke@1 | 212 | return matchingField; |
duke@1 | 213 | } |
duke@1 | 214 | |
duke@1 | 215 | /** |
duke@1 | 216 | * Return the field comment. If there is no serialField comment, return |
duke@1 | 217 | * javadoc comment of corresponding FieldDocImpl. |
duke@1 | 218 | */ |
duke@1 | 219 | public String description() { |
duke@1 | 220 | if (description.length() == 0 && matchingField != null) { |
duke@1 | 221 | |
duke@1 | 222 | //check for javadoc comment of corresponding field. |
duke@1 | 223 | Comment comment = matchingField.comment(); |
duke@1 | 224 | if (comment != null) { |
duke@1 | 225 | return comment.commentText(); |
duke@1 | 226 | } |
duke@1 | 227 | } |
duke@1 | 228 | return description; |
duke@1 | 229 | } |
duke@1 | 230 | |
duke@1 | 231 | /** |
duke@1 | 232 | * Return the kind of this tag. |
duke@1 | 233 | */ |
duke@1 | 234 | public String kind() { |
duke@1 | 235 | return "@serialField"; |
duke@1 | 236 | } |
duke@1 | 237 | |
duke@1 | 238 | /** |
duke@1 | 239 | * Convert this object to a string. |
duke@1 | 240 | */ |
duke@1 | 241 | public String toString() { |
duke@1 | 242 | return name + ":" + text; |
duke@1 | 243 | } |
duke@1 | 244 | |
duke@1 | 245 | /** |
duke@1 | 246 | * Compares this Object with the specified Object for order. Returns a |
duke@1 | 247 | * negative integer, zero, or a positive integer as this Object is less |
duke@1 | 248 | * than, equal to, or greater than the given Object. |
duke@1 | 249 | * <p> |
duke@1 | 250 | * Included to make SerialFieldTagImpl items java.lang.Comparable. |
duke@1 | 251 | * |
duke@1 | 252 | * @param obj the <code>Object</code> to be compared. |
duke@1 | 253 | * @return a negative integer, zero, or a positive integer as this Object |
duke@1 | 254 | * is less than, equal to, or greater than the given Object. |
duke@1 | 255 | * @exception ClassCastException the specified Object's type prevents it |
duke@1 | 256 | * from being compared to this Object. |
duke@1 | 257 | * @since 1.2 |
duke@1 | 258 | */ |
duke@1 | 259 | public int compareTo(Object obj) { |
duke@1 | 260 | return key().compareTo(((SerialFieldTagImpl)obj).key()); |
duke@1 | 261 | } |
duke@1 | 262 | } |