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