Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
vromero@1940 | 1 | /* |
vromero@1940 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
vromero@1940 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
vromero@1940 | 4 | * |
vromero@1940 | 5 | * This code is free software; you can redistribute it and/or modify it |
vromero@1940 | 6 | * under the terms of the GNU General Public License version 2 only, as |
vromero@1940 | 7 | * published by the Free Software Foundation. Oracle designates this |
vromero@1940 | 8 | * particular file as subject to the "Classpath" exception as provided |
vromero@1940 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
vromero@1940 | 10 | * |
vromero@1940 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
vromero@1940 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
vromero@1940 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
vromero@1940 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
vromero@1940 | 15 | * accompanied this code). |
vromero@1940 | 16 | * |
vromero@1940 | 17 | * You should have received a copy of the GNU General Public License version |
vromero@1940 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
vromero@1940 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
vromero@1940 | 20 | * |
vromero@1940 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
vromero@1940 | 22 | * or visit www.oracle.com if you need additional information or have any |
vromero@1940 | 23 | * questions. |
vromero@1940 | 24 | */ |
vromero@1940 | 25 | |
vromero@1940 | 26 | /* |
vromero@1940 | 27 | * @test |
vromero@1940 | 28 | * @bug 8019486 |
vromero@1940 | 29 | * @summary javac, generates erroneous LVT for a test case with lambda code |
vromero@1940 | 30 | * @library /tools/javac/lib |
vromero@1940 | 31 | * @build ToolBox |
vromero@1940 | 32 | * @run main WrongLVTForLambdaTest |
vromero@1940 | 33 | */ |
vromero@1940 | 34 | |
vromero@1940 | 35 | import java.io.File; |
vromero@1940 | 36 | import java.nio.file.Paths; |
vromero@1940 | 37 | |
vromero@1940 | 38 | import com.sun.tools.classfile.ClassFile; |
vromero@1940 | 39 | import com.sun.tools.classfile.Code_attribute; |
vromero@1940 | 40 | import com.sun.tools.classfile.LineNumberTable_attribute; |
vromero@1940 | 41 | import com.sun.tools.classfile.Method; |
vromero@1940 | 42 | import com.sun.tools.javac.util.Assert; |
vromero@1940 | 43 | |
vromero@1940 | 44 | public class WrongLVTForLambdaTest { |
vromero@1940 | 45 | |
vromero@1940 | 46 | static final String testSource = |
vromero@1940 | 47 | /* 01 */ "import java.util.List;\n" + |
vromero@1940 | 48 | /* 02 */ "import java.util.Arrays;\n" + |
vromero@1940 | 49 | /* 03 */ "import java.util.stream.Collectors;\n" + |
vromero@1940 | 50 | /* 04 */ "\n" + |
vromero@1940 | 51 | /* 05 */ "public class Foo {\n" + |
vromero@1940 | 52 | /* 06 */ " void bar(int value) {\n" + |
vromero@1940 | 53 | /* 07 */ " final List<Integer> numbers = Arrays.asList(1, 2, 3);\n" + |
vromero@1940 | 54 | /* 08 */ " final List<Integer> numbersPlusOne = \n" + |
vromero@1940 | 55 | /* 09 */ " numbers.stream().map(number -> number / 1).collect(Collectors.toList());\n" + |
vromero@1940 | 56 | /* 10 */ " }\n" + |
vromero@1940 | 57 | /* 11 */ "}"; |
vromero@1940 | 58 | |
vromero@1940 | 59 | static final int[][] expectedLNT = { |
vromero@1940 | 60 | // {line-number, start-pc}, |
vromero@1940 | 61 | {9, 0}, //number -> number / 1 |
vromero@1940 | 62 | }; |
vromero@1940 | 63 | |
vromero@1940 | 64 | static final String methodToLookFor = "lambda$0"; |
vromero@1940 | 65 | |
vromero@1940 | 66 | public static void main(String[] args) throws Exception { |
vromero@1940 | 67 | new WrongLVTForLambdaTest().run(); |
vromero@1940 | 68 | } |
vromero@1940 | 69 | |
vromero@1940 | 70 | void run() throws Exception { |
vromero@1940 | 71 | compileTestClass(); |
vromero@1940 | 72 | checkClassFile(new File(Paths.get(System.getProperty("user.dir"), |
vromero@1940 | 73 | "Foo.class").toUri()), methodToLookFor); |
vromero@1940 | 74 | } |
vromero@1940 | 75 | |
vromero@1940 | 76 | void compileTestClass() throws Exception { |
vromero@1940 | 77 | ToolBox.JavaToolArgs javacSuccessArgs = |
vromero@1940 | 78 | new ToolBox.JavaToolArgs().setSources(testSource); |
vromero@1940 | 79 | ToolBox.javac(javacSuccessArgs); |
vromero@1940 | 80 | } |
vromero@1940 | 81 | |
vromero@1940 | 82 | void checkClassFile(final File cfile, String methodToFind) throws Exception { |
vromero@1940 | 83 | ClassFile classFile = ClassFile.read(cfile); |
vromero@1940 | 84 | boolean methodFound = false; |
vromero@1940 | 85 | for (Method method : classFile.methods) { |
vromero@1940 | 86 | if (method.getName(classFile.constant_pool).equals(methodToFind)) { |
vromero@1940 | 87 | methodFound = true; |
vromero@1940 | 88 | Code_attribute code = (Code_attribute) method.attributes.get("Code"); |
vromero@1940 | 89 | LineNumberTable_attribute lnt = |
vromero@1940 | 90 | (LineNumberTable_attribute) code.attributes.get("LineNumberTable"); |
vromero@1940 | 91 | Assert.check(lnt.line_number_table_length == expectedLNT.length, |
vromero@1940 | 92 | "The LineNumberTable found has a length different to the expected one"); |
vromero@1940 | 93 | int i = 0; |
vromero@1940 | 94 | for (LineNumberTable_attribute.Entry entry: lnt.line_number_table) { |
vromero@1940 | 95 | Assert.check(entry.line_number == expectedLNT[i][0] && |
vromero@1940 | 96 | entry.start_pc == expectedLNT[i][1], |
vromero@1940 | 97 | "LNT entry at pos " + i + " differ from expected." + |
vromero@1940 | 98 | "Found " + entry.line_number + ":" + entry.start_pc + |
vromero@1940 | 99 | ". Expected " + expectedLNT[i][0] + ":" + expectedLNT[i][1]); |
vromero@1940 | 100 | i++; |
vromero@1940 | 101 | } |
vromero@1940 | 102 | } |
vromero@1940 | 103 | } |
vromero@1940 | 104 | Assert.check(methodFound, "The seek method was not found"); |
vromero@1940 | 105 | } |
vromero@1940 | 106 | |
vromero@1940 | 107 | void error(String msg) { |
vromero@1940 | 108 | throw new AssertionError(msg); |
vromero@1940 | 109 | } |
vromero@1940 | 110 | |
vromero@1940 | 111 | } |