780N/A/*
780N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
780N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
780N/A *
780N/A * This code is free software; you can redistribute it and/or modify it
780N/A * under the terms of the GNU General Public License version 2 only, as
780N/A * published by the Free Software Foundation.
780N/A *
780N/A * This code is distributed in the hope that it will be useful, but WITHOUT
780N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
780N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
780N/A * version 2 for more details (a copy is included in the LICENSE file that
780N/A * accompanied this code).
780N/A *
780N/A * You should have received a copy of the GNU General Public License version
780N/A * 2 along with this work; if not, write to the Free Software Foundation,
780N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
780N/A *
780N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
780N/A * or visit www.oracle.com if you need additional information or have any
780N/A * questions.
780N/A */
780N/A
780N/A/*
780N/A * @test
780N/A * @bug 7005371
780N/A * @summary Multicatch: assertion error while generating LocalVariableTypeTable attribute
780N/A * @compile -g SubTest.java
780N/A * @run main T7005371
780N/A */
780N/A
780N/Aimport com.sun.tools.classfile.Attribute;
780N/Aimport com.sun.tools.classfile.ClassFile;
780N/Aimport com.sun.tools.classfile.Code_attribute;
780N/Aimport com.sun.tools.classfile.LocalVariableTypeTable_attribute;
780N/Aimport com.sun.tools.classfile.Method;
780N/A
780N/Aimport java.io.*;
780N/A
780N/Apublic class T7005371 {
780N/A
780N/A static final String SUBTEST_NAME = SubTest.class.getName() + ".class";
780N/A static final String TEST_METHOD_NAME = "test";
780N/A static final int LVT_LENGTH = 1;
780N/A static final String LVT_SIG_TYPE = "Ljava/util/List<Ljava/lang/String;>;";
780N/A
780N/A
780N/A public static void main(String... args) throws Exception {
780N/A new T7005371().run();
780N/A }
780N/A
780N/A public void run() throws Exception {
780N/A String workDir = System.getProperty("test.classes");
780N/A System.out.println(workDir);
780N/A File compiledTest = new File(workDir, SUBTEST_NAME);
780N/A verifyLocalVariableTypeTableAttr(compiledTest);
780N/A }
780N/A
780N/A void verifyLocalVariableTypeTableAttr(File f) {
780N/A System.err.println("verify: " + f);
780N/A try {
780N/A ClassFile cf = ClassFile.read(f);
780N/A Method testMethod = null;
780N/A for (Method m : cf.methods) {
780N/A if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
780N/A testMethod = m;
780N/A break;
780N/A }
780N/A }
780N/A if (testMethod == null) {
780N/A throw new Error("Missing method: " + TEST_METHOD_NAME);
780N/A }
780N/A Code_attribute code = (Code_attribute)testMethod.attributes.get(Attribute.Code);
780N/A if (code == null) {
780N/A throw new Error("Missing Code attribute for method: " + TEST_METHOD_NAME);
780N/A }
780N/A LocalVariableTypeTable_attribute lvt_table =
780N/A (LocalVariableTypeTable_attribute)code.attributes.get(Attribute.LocalVariableTypeTable);
780N/A if (lvt_table == null) {
780N/A throw new Error("Missing LocalVariableTypeTable attribute for method: " + TEST_METHOD_NAME);
780N/A }
780N/A if (lvt_table.local_variable_table_length != LVT_LENGTH) {
780N/A throw new Error("LocalVariableTypeTable has wrong size" +
780N/A "\nfound: " + lvt_table.local_variable_table_length +
780N/A "\nrequired: " + LVT_LENGTH);
780N/A }
780N/A String sig =
780N/A cf.constant_pool.getUTF8Value(lvt_table.local_variable_table[0].signature_index);
780N/A
780N/A if (sig == null || !sig.equals(LVT_SIG_TYPE)) {
780N/A throw new Error("LocalVariableTypeTable has wrong signature" +
780N/A "\nfound: " + sig +
780N/A "\nrequired: " + LVT_SIG_TYPE);
780N/A }
780N/A } catch (Exception e) {
780N/A e.printStackTrace();
780N/A throw new Error("error reading " + f +": " + e);
780N/A }
780N/A }
780N/A}