/* * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 7047734 8027660 8037937 8047719 8058708 8064857 * @summary The LVT is not generated correctly during some try/catch scenarios * javac crash while creating LVT entry for a local variable defined in * an inner block * @library /tools/javac/lib * @modules jdk.jdeps/com.sun.tools.classfile * @build JavacTestingAbstractProcessor LVTHarness * @run main LVTHarness
*/
File javaFile = new File(jfo.getName());
File classFile = new File(javaFile.getName().replace(".java", ".class"));
checkClassFile(classFile);
//check all candidates have been used up for (Map.Entry<ElementKey, AliveRanges> entry : aliveRangeMap.entrySet()) { if (!seenAliveRanges.contains(entry.getKey())) {
error("Redundant @AliveRanges annotation on method " +
entry.getKey().elem + " with key " + entry.getKey());
}
}
}
//lets get all the methods in the class file. for (Method method : classFile.methods) { for (ElementKey elementKey: aliveRangeMap.keySet()) {
String methodDesc = method.getName(constantPool) +
method.descriptor.getParameterTypes(constantPool).replace(" ", ""); if (methodDesc.equals(elementKey.elem.toString())) {
checkMethod(constantPool, method, aliveRangeMap.get(elementKey));
seenAliveRanges.add(elementKey);
}
}
}
}
// infoFromRanges most be contained in infoFromLVT int i = 0; int j = 0; while (i < infoFromRanges.size() && j < infoFromLVT.size()) { int comparison = infoFromRanges.get(i).compareTo(infoFromLVT.get(j)); if (comparison == 0) {
i++; j++;
} elseif (comparison > 0) {
j++;
} else { break;
}
}
if (i < infoFromRanges.size()) {
error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString());
}
}
List<String> convertToStringList(AliveRanges ranges) {
List<String> result = new ArrayList<>(); for (Annotation anno : ranges.value()) {
AliveRange range = (AliveRange)anno;
String str = formatLocalVariableData(range.varName(),
range.bytecodeStart(), range.bytecodeLength());
result.add(str);
}
Collections.sort(result); return result;
}
String formatLocalVariableData(String varName, int start, int length) {
StringBuilder sb = new StringBuilder()
.append("var name: ").append(varName)
.append(" start: ").append(start)
.append(" length: ").append(length); return sb.toString();
}
protectedvoid error(List<String> infoFromLVT, List<String> infoFromRanges, String methodName) {
nerrors++;
System.err.printf("Error occurred while checking file: %s\n", jfo.getName());
System.err.printf("at method: %s\n", methodName);
System.err.println("The range info from the annotations is");
printStringListToErrOutput(infoFromRanges);
System.err.println();
System.err.println("And the range info from the class file is");
printStringListToErrOutput(infoFromLVT);
System.err.println();
}
void printStringListToErrOutput(List<String> list) { for (String s : list) {
System.err.println("\t" + s);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.