langtools/test/tools/javac/multicatch/7005371/T7005371.java
author mchung
Wed, 27 May 2015 13:25:18 -0700
changeset 30846 2b3f379840f0
parent 30730 d3ce7619db2c
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:
7629
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 7629
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
7629
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
     4
 *
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
     8
 *
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    13
 * accompanied this code).
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    14
 *
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    18
 *
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    21
 * questions.
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    22
 */
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    23
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    24
/*
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    25
 * @test
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    26
 * @bug 7005371
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    27
 * @summary  Multicatch: assertion error while generating LocalVariableTypeTable attribute
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    28
 * @modules jdk.jdeps/com.sun.tools.classfile
7629
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    29
 * @compile -g SubTest.java
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    30
 * @run main T7005371
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    31
 */
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    32
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    33
import com.sun.tools.classfile.Attribute;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    34
import com.sun.tools.classfile.ClassFile;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    35
import com.sun.tools.classfile.Code_attribute;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    36
import com.sun.tools.classfile.LocalVariableTypeTable_attribute;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    37
import com.sun.tools.classfile.Method;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    38
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    39
import java.io.*;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    40
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    41
public class T7005371 {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    42
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    43
    static final String SUBTEST_NAME = SubTest.class.getName() + ".class";
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    44
    static final String TEST_METHOD_NAME = "test";
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    45
    static final int LVT_LENGTH = 1;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    46
    static final String LVT_SIG_TYPE = "Ljava/util/List<Ljava/lang/String;>;";
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    47
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    48
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    49
    public static void main(String... args) throws Exception {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    50
        new T7005371().run();
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    51
    }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    52
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    53
    public void run() throws Exception {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    54
        String workDir = System.getProperty("test.classes");
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    55
        System.out.println(workDir);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    56
        File compiledTest = new File(workDir, SUBTEST_NAME);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    57
        verifyLocalVariableTypeTableAttr(compiledTest);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    58
    }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    59
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    60
    void verifyLocalVariableTypeTableAttr(File f) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    61
        System.err.println("verify: " + f);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    62
        try {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    63
            ClassFile cf = ClassFile.read(f);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    64
            Method testMethod = null;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    65
            for (Method m : cf.methods) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    66
                if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    67
                    testMethod = m;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    68
                    break;
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    69
                }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    70
            }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    71
            if (testMethod == null) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    72
                throw new Error("Missing method: " + TEST_METHOD_NAME);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    73
            }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    74
            Code_attribute code = (Code_attribute)testMethod.attributes.get(Attribute.Code);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    75
            if (code == null) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    76
                throw new Error("Missing Code attribute for method: " + TEST_METHOD_NAME);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    77
            }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    78
            LocalVariableTypeTable_attribute lvt_table =
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    79
                    (LocalVariableTypeTable_attribute)code.attributes.get(Attribute.LocalVariableTypeTable);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    80
            if (lvt_table == null) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    81
                throw new Error("Missing LocalVariableTypeTable attribute for method: " + TEST_METHOD_NAME);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    82
            }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    83
            if (lvt_table.local_variable_table_length != LVT_LENGTH) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    84
                throw new Error("LocalVariableTypeTable has wrong size" +
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    85
                        "\nfound: " + lvt_table.local_variable_table_length +
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    86
                        "\nrequired: " + LVT_LENGTH);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    87
            }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    88
            String sig =
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    89
                    cf.constant_pool.getUTF8Value(lvt_table.local_variable_table[0].signature_index);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    90
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    91
            if (sig == null || !sig.equals(LVT_SIG_TYPE)) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    92
                throw new Error("LocalVariableTypeTable has wrong signature" +
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    93
                        "\nfound: " + sig +
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    94
                        "\nrequired: " + LVT_SIG_TYPE);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    95
            }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    96
        } catch (Exception e) {
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    97
            e.printStackTrace();
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    98
            throw new Error("error reading " + f +": " + e);
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
    99
        }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
   100
    }
4662e86bff2e 7005371: Multicatch: assertion error while generating LocalVariableTypeTable attribute
mcimadamore
parents:
diff changeset
   101
}