Tue, 26 Jan 2016 21:08:18 +0000
8130304: Inference: NodeNotFoundException thrown with deep generic method call chain
Summary: Bug in Tarjan implementation is generating node ids which can overflow 32 bits
Reviewed-by: vromero
jjg@73 | 1 | /* |
jjg@1358 | 2 | * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
jjg@73 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@73 | 4 | * |
jjg@73 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@73 | 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@73 | 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@73 | 10 | * |
jjg@73 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@73 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@73 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@73 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@73 | 15 | * accompanied this code). |
jjg@73 | 16 | * |
jjg@73 | 17 | * You should have received a copy of the GNU General Public License version |
jjg@73 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@73 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@73 | 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@73 | 24 | */ |
jjg@73 | 25 | |
jjg@73 | 26 | package com.sun.tools.javac.util; |
jjg@73 | 27 | |
jjg@73 | 28 | import java.util.HashMap; |
jjg@73 | 29 | import java.util.Map; |
jjg@73 | 30 | import javax.tools.JavaFileObject; |
jjg@73 | 31 | |
jjg@612 | 32 | import com.sun.tools.javac.code.Lint.LintCategory; |
jjg@726 | 33 | import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; |
jjg@73 | 34 | import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
jjg@73 | 35 | import com.sun.tools.javac.util.JCDiagnostic.SimpleDiagnosticPosition; |
jjg@73 | 36 | |
jjg@73 | 37 | |
jjg@73 | 38 | /** |
jjg@73 | 39 | * A base class for error logs. Reports errors and warnings, and |
jjg@73 | 40 | * keeps track of error numbers and positions. |
jjg@73 | 41 | * |
jjg@581 | 42 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 43 | * If you write code that depends on this, you do so at your own risk. |
jjg@73 | 44 | * This code and its internal interfaces are subject to change or |
jjg@73 | 45 | * deletion without notice.</b> |
jjg@73 | 46 | */ |
jjg@73 | 47 | public abstract class AbstractLog { |
jjg@73 | 48 | AbstractLog(JCDiagnostic.Factory diags) { |
jjg@73 | 49 | this.diags = diags; |
jjg@73 | 50 | sourceMap = new HashMap<JavaFileObject, DiagnosticSource>(); |
jjg@73 | 51 | } |
jjg@73 | 52 | |
jjg@73 | 53 | /** Re-assign source, returning previous setting. |
jjg@73 | 54 | */ |
jjg@73 | 55 | public JavaFileObject useSource(JavaFileObject file) { |
jjg@73 | 56 | JavaFileObject prev = (source == null ? null : source.getFile()); |
jjg@73 | 57 | source = getSource(file); |
jjg@73 | 58 | return prev; |
jjg@73 | 59 | } |
jjg@73 | 60 | |
jjg@73 | 61 | protected DiagnosticSource getSource(JavaFileObject file) { |
jjg@73 | 62 | if (file == null) |
mcimadamore@303 | 63 | return DiagnosticSource.NO_SOURCE; |
jjg@73 | 64 | DiagnosticSource s = sourceMap.get(file); |
jjg@73 | 65 | if (s == null) { |
jjg@73 | 66 | s = new DiagnosticSource(file, this); |
jjg@73 | 67 | sourceMap.put(file, s); |
jjg@73 | 68 | } |
jjg@73 | 69 | return s; |
jjg@73 | 70 | } |
jjg@73 | 71 | |
mcimadamore@168 | 72 | /** Return the underlying diagnostic source |
mcimadamore@168 | 73 | */ |
mcimadamore@168 | 74 | public DiagnosticSource currentSource() { |
mcimadamore@168 | 75 | return source; |
mcimadamore@168 | 76 | } |
mcimadamore@168 | 77 | |
jjg@73 | 78 | /** Report an error, unless another error was already reported at same |
jjg@73 | 79 | * source position. |
jjg@73 | 80 | * @param key The key for the localized error message. |
jjg@73 | 81 | * @param args Fields of the error message. |
jjg@73 | 82 | */ |
jjg@73 | 83 | public void error(String key, Object ... args) { |
jjg@73 | 84 | report(diags.error(source, null, key, args)); |
jjg@73 | 85 | } |
jjg@73 | 86 | |
jjg@73 | 87 | /** Report an error, unless another error was already reported at same |
jjg@73 | 88 | * source position. |
jjg@73 | 89 | * @param pos The source position at which to report the error. |
jjg@73 | 90 | * @param key The key for the localized error message. |
jjg@73 | 91 | * @param args Fields of the error message. |
jjg@73 | 92 | */ |
jjg@73 | 93 | public void error(DiagnosticPosition pos, String key, Object ... args) { |
jjg@73 | 94 | report(diags.error(source, pos, key, args)); |
jjg@73 | 95 | } |
jjg@73 | 96 | |
jjg@73 | 97 | /** Report an error, unless another error was already reported at same |
jjg@73 | 98 | * source position. |
ksrini@1074 | 99 | * @param flag A flag to set on the diagnostic |
ksrini@1074 | 100 | * @param pos The source position at which to report the error. |
ksrini@1074 | 101 | * @param key The key for the localized error message. |
ksrini@1074 | 102 | * @param args Fields of the error message. |
ksrini@1074 | 103 | */ |
ksrini@1074 | 104 | public void error(DiagnosticFlag flag, DiagnosticPosition pos, String key, Object ... args) { |
ksrini@1074 | 105 | JCDiagnostic d = diags.error(source, pos, key, args); |
ksrini@1074 | 106 | d.setFlag(flag); |
ksrini@1074 | 107 | report(d); |
ksrini@1074 | 108 | } |
ksrini@1074 | 109 | |
ksrini@1074 | 110 | /** Report an error, unless another error was already reported at same |
ksrini@1074 | 111 | * source position. |
jjg@73 | 112 | * @param pos The source position at which to report the error. |
jjg@73 | 113 | * @param key The key for the localized error message. |
jjg@73 | 114 | * @param args Fields of the error message. |
jjg@73 | 115 | */ |
jjg@73 | 116 | public void error(int pos, String key, Object ... args) { |
jjg@73 | 117 | report(diags.error(source, wrap(pos), key, args)); |
jjg@73 | 118 | } |
jjg@73 | 119 | |
jjg@726 | 120 | /** Report an error, unless another error was already reported at same |
jjg@726 | 121 | * source position. |
jjg@726 | 122 | * @param flag A flag to set on the diagnostic |
jjg@726 | 123 | * @param pos The source position at which to report the error. |
jjg@726 | 124 | * @param key The key for the localized error message. |
jjg@726 | 125 | * @param args Fields of the error message. |
jjg@726 | 126 | */ |
jjg@726 | 127 | public void error(DiagnosticFlag flag, int pos, String key, Object ... args) { |
jjg@726 | 128 | JCDiagnostic d = diags.error(source, wrap(pos), key, args); |
jjg@726 | 129 | d.setFlag(flag); |
jjg@726 | 130 | report(d); |
jjg@726 | 131 | } |
jjg@726 | 132 | |
jjg@73 | 133 | /** Report a warning, unless suppressed by the -nowarn option or the |
jjg@73 | 134 | * maximum number of warnings has been reached. |
jjg@73 | 135 | * @param key The key for the localized warning message. |
jjg@73 | 136 | * @param args Fields of the warning message. |
jjg@73 | 137 | */ |
jjg@73 | 138 | public void warning(String key, Object ... args) { |
jjg@73 | 139 | report(diags.warning(source, null, key, args)); |
jjg@73 | 140 | } |
jjg@73 | 141 | |
jjg@612 | 142 | /** Report a lint warning, unless suppressed by the -nowarn option or the |
jjg@612 | 143 | * maximum number of warnings has been reached. |
jjg@612 | 144 | * @param lc The lint category for the diagnostic |
jjg@612 | 145 | * @param key The key for the localized warning message. |
jjg@612 | 146 | * @param args Fields of the warning message. |
jjg@612 | 147 | */ |
jjg@612 | 148 | public void warning(LintCategory lc, String key, Object ... args) { |
jjg@612 | 149 | report(diags.warning(lc, key, args)); |
jjg@612 | 150 | } |
jjg@612 | 151 | |
jjg@73 | 152 | /** Report a warning, unless suppressed by the -nowarn option or the |
jjg@73 | 153 | * maximum number of warnings has been reached. |
jjg@73 | 154 | * @param pos The source position at which to report the warning. |
jjg@73 | 155 | * @param key The key for the localized warning message. |
jjg@73 | 156 | * @param args Fields of the warning message. |
jjg@73 | 157 | */ |
jjg@73 | 158 | public void warning(DiagnosticPosition pos, String key, Object ... args) { |
jjg@73 | 159 | report(diags.warning(source, pos, key, args)); |
jjg@73 | 160 | } |
jjg@73 | 161 | |
jjg@612 | 162 | /** Report a lint warning, unless suppressed by the -nowarn option or the |
jjg@612 | 163 | * maximum number of warnings has been reached. |
jjg@612 | 164 | * @param lc The lint category for the diagnostic |
jjg@612 | 165 | * @param pos The source position at which to report the warning. |
jjg@612 | 166 | * @param key The key for the localized warning message. |
jjg@612 | 167 | * @param args Fields of the warning message. |
jjg@612 | 168 | */ |
jjg@612 | 169 | public void warning(LintCategory lc, DiagnosticPosition pos, String key, Object ... args) { |
jjg@612 | 170 | report(diags.warning(lc, source, pos, key, args)); |
jjg@612 | 171 | } |
jjg@612 | 172 | |
jjg@73 | 173 | /** Report a warning, unless suppressed by the -nowarn option or the |
jjg@73 | 174 | * maximum number of warnings has been reached. |
jjg@73 | 175 | * @param pos The source position at which to report the warning. |
jjg@73 | 176 | * @param key The key for the localized warning message. |
jjg@73 | 177 | * @param args Fields of the warning message. |
jjg@73 | 178 | */ |
jjg@73 | 179 | public void warning(int pos, String key, Object ... args) { |
jjg@73 | 180 | report(diags.warning(source, wrap(pos), key, args)); |
jjg@73 | 181 | } |
jjg@73 | 182 | |
jjg@73 | 183 | /** Report a warning. |
jjg@73 | 184 | * @param pos The source position at which to report the warning. |
jjg@73 | 185 | * @param key The key for the localized warning message. |
jjg@73 | 186 | * @param args Fields of the warning message. |
jjg@73 | 187 | */ |
jjg@73 | 188 | public void mandatoryWarning(DiagnosticPosition pos, String key, Object ... args) { |
jjg@73 | 189 | report(diags.mandatoryWarning(source, pos, key, args)); |
jjg@73 | 190 | } |
jjg@73 | 191 | |
jjg@612 | 192 | /** Report a warning. |
jjg@612 | 193 | * @param lc The lint category for the diagnostic |
jjg@612 | 194 | * @param pos The source position at which to report the warning. |
jjg@612 | 195 | * @param key The key for the localized warning message. |
jjg@612 | 196 | * @param args Fields of the warning message. |
jjg@612 | 197 | */ |
jjg@612 | 198 | public void mandatoryWarning(LintCategory lc, DiagnosticPosition pos, String key, Object ... args) { |
jjg@612 | 199 | report(diags.mandatoryWarning(lc, source, pos, key, args)); |
jjg@612 | 200 | } |
jjg@612 | 201 | |
jjg@73 | 202 | /** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
jjg@73 | 203 | * @param key The key for the localized notification message. |
jjg@73 | 204 | * @param args Fields of the notint an error or warning message: |
jjg@73 | 205 | */ |
jjg@73 | 206 | public void note(String key, Object ... args) { |
jjg@73 | 207 | report(diags.note(source, null, key, args)); |
jjg@73 | 208 | } |
jjg@73 | 209 | |
jjg@73 | 210 | /** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
jjg@73 | 211 | * @param key The key for the localized notification message. |
jjg@73 | 212 | * @param args Fields of the notification message. |
jjg@73 | 213 | */ |
jjg@73 | 214 | public void note(DiagnosticPosition pos, String key, Object ... args) { |
jjg@73 | 215 | report(diags.note(source, pos, key, args)); |
jjg@73 | 216 | } |
jjg@73 | 217 | |
jjg@73 | 218 | /** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
jjg@73 | 219 | * @param key The key for the localized notification message. |
jjg@73 | 220 | * @param args Fields of the notification message. |
jjg@73 | 221 | */ |
jjg@73 | 222 | public void note(int pos, String key, Object ... args) { |
jjg@73 | 223 | report(diags.note(source, wrap(pos), key, args)); |
jjg@73 | 224 | } |
jjg@73 | 225 | |
jjg@73 | 226 | /** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
jjg@73 | 227 | * @param key The key for the localized notification message. |
jjg@73 | 228 | * @param args Fields of the notification message. |
jjg@73 | 229 | */ |
jjg@73 | 230 | public void note(JavaFileObject file, String key, Object ... args) { |
jjg@73 | 231 | report(diags.note(getSource(file), null, key, args)); |
jjg@73 | 232 | } |
jjg@73 | 233 | |
jjg@73 | 234 | /** Provide a non-fatal notification, unless suppressed by the -nowarn option. |
jjg@73 | 235 | * @param key The key for the localized notification message. |
jjg@73 | 236 | * @param args Fields of the notification message. |
jjg@73 | 237 | */ |
jjg@73 | 238 | public void mandatoryNote(final JavaFileObject file, String key, Object ... args) { |
jjg@73 | 239 | report(diags.mandatoryNote(getSource(file), key, args)); |
jjg@73 | 240 | } |
jjg@73 | 241 | |
jjg@73 | 242 | protected abstract void report(JCDiagnostic diagnostic); |
jjg@73 | 243 | |
jjg@73 | 244 | protected abstract void directError(String key, Object... args); |
jjg@73 | 245 | |
jjg@73 | 246 | private DiagnosticPosition wrap(int pos) { |
jjg@73 | 247 | return (pos == Position.NOPOS ? null : new SimpleDiagnosticPosition(pos)); |
jjg@73 | 248 | } |
jjg@73 | 249 | |
jjg@73 | 250 | /** Factory for diagnostics |
jjg@73 | 251 | */ |
jjg@73 | 252 | protected JCDiagnostic.Factory diags; |
jjg@73 | 253 | |
jjg@73 | 254 | /** The file that's currently being translated. |
jjg@73 | 255 | */ |
jjg@73 | 256 | protected DiagnosticSource source; |
jjg@73 | 257 | |
jjg@73 | 258 | /** A cache of lightweight DiagnosticSource objects. |
jjg@73 | 259 | */ |
jjg@73 | 260 | protected Map<JavaFileObject, DiagnosticSource> sourceMap; |
jjg@73 | 261 | } |