Fri, 24 Apr 2020 03:58:51 +0100
Merge
mcimadamore@2789 | 1 | /* |
mcimadamore@2789 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@2789 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@2789 | 4 | * |
mcimadamore@2789 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@2789 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@2789 | 7 | * published by the Free Software Foundation. Oracle designates this |
mcimadamore@2789 | 8 | * particular file as subject to the "Classpath" exception as provided |
mcimadamore@2789 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
mcimadamore@2789 | 10 | * |
mcimadamore@2789 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@2789 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@2789 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@2789 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@2789 | 15 | * accompanied this code). |
mcimadamore@2789 | 16 | * |
mcimadamore@2789 | 17 | * You should have received a copy of the GNU General Public License version |
mcimadamore@2789 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@2789 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@2789 | 20 | * |
mcimadamore@2789 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mcimadamore@2789 | 22 | * or visit www.oracle.com if you need additional information or have any |
mcimadamore@2789 | 23 | * questions. |
mcimadamore@2789 | 24 | */ |
mcimadamore@2789 | 25 | |
mcimadamore@2789 | 26 | /* |
mcimadamore@2789 | 27 | * @test |
mcimadamore@2789 | 28 | * @bug 8061778 |
mcimadamore@2789 | 29 | * @summary Wrong LineNumberTable for default constructors |
mcimadamore@2789 | 30 | */ |
mcimadamore@2789 | 31 | |
mcimadamore@2789 | 32 | import com.sun.tools.classfile.ClassFile; |
mcimadamore@2789 | 33 | import com.sun.tools.classfile.ConstantPoolException; |
mcimadamore@2789 | 34 | import com.sun.tools.classfile.Method; |
mcimadamore@2789 | 35 | import com.sun.tools.classfile.Attribute; |
mcimadamore@2789 | 36 | import com.sun.tools.classfile.Code_attribute; |
mcimadamore@2789 | 37 | import com.sun.tools.classfile.LineNumberTable_attribute; |
mcimadamore@2789 | 38 | import com.sun.tools.classfile.LineNumberTable_attribute.Entry; |
mcimadamore@2789 | 39 | |
mcimadamore@2789 | 40 | import java.io.IOException; |
mcimadamore@2789 | 41 | |
mcimadamore@2789 | 42 | public class NestedLineNumberTest { |
mcimadamore@2789 | 43 | |
mcimadamore@2789 | 44 | public static void main(String[] args) throws Exception { |
mcimadamore@2789 | 45 | Entry[] lines = findEntries(); |
mcimadamore@2789 | 46 | if (lines == null || lines.length != 1) { |
mcimadamore@2789 | 47 | int found = lines == null ? 0 : lines.length; |
mcimadamore@2789 | 48 | error(String.format("LineNumberTable contains wrong number of entries - expected %d, found %d", 1, found)); |
mcimadamore@2789 | 49 | } |
mcimadamore@2789 | 50 | |
mcimadamore@2789 | 51 | int line = lines[0].line_number; |
mcimadamore@2789 | 52 | if (line != 78) { |
mcimadamore@2789 | 53 | error(String.format("LineNumberTable contains wrong line number - expected %d, found %d", 78, line)); |
mcimadamore@2789 | 54 | } |
mcimadamore@2789 | 55 | } |
mcimadamore@2789 | 56 | |
mcimadamore@2789 | 57 | static Entry[] findEntries() throws IOException, ConstantPoolException { |
mcimadamore@2789 | 58 | ClassFile self = ClassFile.read(NestedLineNumberTest.Test.class.getResourceAsStream("NestedLineNumberTest$Test.class")); |
mcimadamore@2789 | 59 | for (Method m : self.methods) { |
mcimadamore@2789 | 60 | if ("<init>".equals(m.getName(self.constant_pool))) { |
mcimadamore@2789 | 61 | Code_attribute code_attribute = (Code_attribute)m.attributes.get(Attribute.Code); |
mcimadamore@2789 | 62 | for (Attribute at : code_attribute.attributes) { |
mcimadamore@2789 | 63 | if (Attribute.LineNumberTable.equals(at.getName(self.constant_pool))) { |
mcimadamore@2789 | 64 | return ((LineNumberTable_attribute)at).line_number_table; |
mcimadamore@2789 | 65 | } |
mcimadamore@2789 | 66 | } |
mcimadamore@2789 | 67 | } |
mcimadamore@2789 | 68 | } |
mcimadamore@2789 | 69 | return null; |
mcimadamore@2789 | 70 | } |
mcimadamore@2789 | 71 | |
mcimadamore@2789 | 72 | static void error(String msg) { |
mcimadamore@2789 | 73 | throw new AssertionError(msg); |
mcimadamore@2789 | 74 | } |
mcimadamore@2789 | 75 | |
mcimadamore@2789 | 76 | // The default constructor in this class should get only one LineNumberTable entry, |
mcimadamore@2789 | 77 | // pointing to the first line of the declaration of class Test. |
mcimadamore@2789 | 78 | static class Test { |
mcimadamore@2789 | 79 | static class Empty { } |
mcimadamore@2789 | 80 | } |
mcimadamore@2789 | 81 | } |