Tue, 28 May 2013 12:46:10 +0100
6970173: Debug pointer at bad position
Reviewed-by: mcimadamore
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Mon May 27 13:44:14 2013 +0100 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Tue May 28 12:46:10 2013 +0100 1.3 @@ -2931,7 +2931,7 @@ 1.4 } 1.5 result = 1.6 make.If(cond, 1.7 - make_at(detailPos). 1.8 + make_at(tree). 1.9 Throw(makeNewClass(syms.assertionErrorType, exnArgs)), 1.10 null); 1.11 } else {
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/T6970173/DebugPointerAtBadPositionTest.java Tue May 28 12:46:10 2013 +0100 2.3 @@ -0,0 +1,112 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 6970173 2.30 + * @summary Debug pointer at bad position 2.31 + * @library /tools/javac/lib 2.32 + * @build ToolBox 2.33 + * @run main DebugPointerAtBadPositionTest 2.34 + */ 2.35 + 2.36 +import java.io.File; 2.37 +import java.nio.file.Paths; 2.38 + 2.39 +import com.sun.tools.classfile.ClassFile; 2.40 +import com.sun.tools.classfile.Code_attribute; 2.41 +import com.sun.tools.classfile.LineNumberTable_attribute; 2.42 +import com.sun.tools.classfile.Method; 2.43 +import com.sun.tools.javac.util.Assert; 2.44 + 2.45 +public class DebugPointerAtBadPositionTest { 2.46 + 2.47 + static final String testSource = 2.48 + "public class AssertionTest {\n" + 2.49 + " void lookForThisMethod() {\n" + 2.50 + " int i;\n" + 2.51 + " i = 33;\n" + 2.52 + " assert // line 5\n" + 2.53 + " i < 89:\n" + 2.54 + " i < 100; // line 7\n" + 2.55 + " }\n" + 2.56 + "}"; 2.57 + 2.58 + static final int[][] expectedLNT = { 2.59 + {4, 0}, 2.60 + {5, 3}, 2.61 + {8, 34} 2.62 + }; 2.63 + 2.64 + static final String methodToLookFor = "lookForThisMethod"; 2.65 + static final String seekMethodNotFoundMsg = 2.66 + "The seek method was not found"; 2.67 + static final String foundLNTLengthDifferentThanExpMsg = 2.68 + "The LineNumberTable found has a length different to the expected one"; 2.69 + 2.70 + public static void main(String[] args) throws Exception { 2.71 + new DebugPointerAtBadPositionTest().run(); 2.72 + } 2.73 + 2.74 + void run() throws Exception { 2.75 + compileTestClass(); 2.76 + checkClassFile(new File(Paths.get(System.getProperty("user.dir"), 2.77 + "AssertionTest.class").toUri()), methodToLookFor); 2.78 + } 2.79 + 2.80 + void compileTestClass() throws Exception { 2.81 + ToolBox.JavaToolArgs javacSuccessArgs = 2.82 + new ToolBox.JavaToolArgs().setSources(testSource); 2.83 + ToolBox.javac(javacSuccessArgs); 2.84 + } 2.85 + 2.86 + void checkClassFile(final File cfile, String methodToFind) throws Exception { 2.87 + ClassFile classFile = ClassFile.read(cfile); 2.88 + boolean methodFound = false; 2.89 + for (Method method : classFile.methods) { 2.90 + if (method.getName(classFile.constant_pool).equals(methodToFind)) { 2.91 + methodFound = true; 2.92 + Code_attribute code = (Code_attribute) method.attributes.get("Code"); 2.93 + LineNumberTable_attribute lnt = 2.94 + (LineNumberTable_attribute) code.attributes.get("LineNumberTable"); 2.95 + Assert.check(lnt.line_number_table_length == expectedLNT.length, 2.96 + foundLNTLengthDifferentThanExpMsg); 2.97 + int i = 0; 2.98 + for (LineNumberTable_attribute.Entry entry: lnt.line_number_table) { 2.99 + Assert.check(entry.line_number == expectedLNT[i][0] && 2.100 + entry.start_pc == expectedLNT[i][1], 2.101 + "LNT entry at pos " + i + " differ from expected." + 2.102 + "Found " + entry.line_number + ":" + entry.start_pc + 2.103 + ". Expected " + expectedLNT[i][0] + ":" + expectedLNT[i][1]); 2.104 + i++; 2.105 + } 2.106 + } 2.107 + } 2.108 + Assert.check(methodFound, seekMethodNotFoundMsg); 2.109 + } 2.110 + 2.111 + void error(String msg) { 2.112 + throw new AssertionError(msg); 2.113 + } 2.114 + 2.115 +}