test/tools/javap/classfile/T6887895.java

changeset 422
e526e39579ae
child 554
9d9f26857129
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javap/classfile/T6887895.java	Tue Oct 13 14:02:53 2009 -0700
     1.3 @@ -0,0 +1,121 @@
     1.4 +/*
     1.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 6887895
    1.30 + * @summary CONSTANT_Class_info getBaseName does not handle arrays of primitives correctly
    1.31 + */
    1.32 +
    1.33 +import java.io.*;
    1.34 +import java.net.*;
    1.35 +import java.util.*;
    1.36 +import com.sun.tools.classfile.*;
    1.37 +import com.sun.tools.classfile.ConstantPool.*;
    1.38 +
    1.39 +public class T6887895 {
    1.40 +    public static void main(String[] args) throws Exception {
    1.41 +        new T6887895().run();
    1.42 +    }
    1.43 +
    1.44 +    void run() throws Exception {
    1.45 +        Set<String> found = new TreeSet<String>();
    1.46 +
    1.47 +        ClassFile cf = getClassFile("T6887895$Test.class");
    1.48 +        for (CPInfo cpInfo: cf.constant_pool.entries()) {
    1.49 +            if (cpInfo instanceof CONSTANT_Class_info) {
    1.50 +                CONSTANT_Class_info info = (CONSTANT_Class_info) cpInfo;
    1.51 +                String name = info.getName();
    1.52 +                String baseName = info.getBaseName();
    1.53 +                System.out.println("found: " + name + " " + baseName);
    1.54 +                if (baseName != null)
    1.55 +                    found.add(baseName);
    1.56 +            }
    1.57 +        }
    1.58 +
    1.59 +        String[] expectNames = {
    1.60 +            "java/lang/Object",
    1.61 +            "java/lang/String",
    1.62 +            "T6887895",
    1.63 +            "T6887895$Test"
    1.64 +        };
    1.65 +
    1.66 +        Set<String> expect = new TreeSet<String>(Arrays.asList(expectNames));
    1.67 +        if (!found.equals(expect)) {
    1.68 +            System.err.println("found: " + found);
    1.69 +            System.err.println("expect: " + expect);
    1.70 +            throw new Exception("unexpected values found");
    1.71 +        }
    1.72 +    }
    1.73 +
    1.74 +    ClassFile getClassFile(String name) throws IOException, ConstantPoolException {
    1.75 +        URL url = getClass().getResource(name);
    1.76 +        InputStream in = url.openStream();
    1.77 +        try {
    1.78 +            return ClassFile.read(in);
    1.79 +        } finally {
    1.80 +            in.close();
    1.81 +        }
    1.82 +    }
    1.83 +
    1.84 +    class Test {
    1.85 +        void m() {
    1.86 +            boolean[] az = new boolean[0];
    1.87 +            boolean[][] aaz = new boolean[0][];
    1.88 +            boolean[][][] aaaz = new boolean[0][][];
    1.89 +
    1.90 +            byte[] ab = new byte[0];
    1.91 +            byte[][] aab = new byte[0][];
    1.92 +            byte[][][] aaab = new byte[0][][];
    1.93 +
    1.94 +            char[] ac = new char[0];
    1.95 +            char[][] aac = new char[0][];
    1.96 +            char[][][] aaac = new char[0][][];
    1.97 +
    1.98 +            double[] ad = new double[0];
    1.99 +            double[][] aad = new double[0][];
   1.100 +            double[][][] aaad = new double[0][][];
   1.101 +
   1.102 +            float[] af = new float[0];
   1.103 +            float[][] aaf = new float[0][];
   1.104 +            float[][][] aaaf = new float[0][][];
   1.105 +
   1.106 +            int[] ai = new int[0];
   1.107 +            int[][] aai = new int[0][];
   1.108 +            int[][][] aaai = new int[0][][];
   1.109 +
   1.110 +            long[] al = new long[0];
   1.111 +            long[][] aal = new long[0][];
   1.112 +            long[][][] aaal = new long[0][][];
   1.113 +
   1.114 +            short[] as = new short[0];
   1.115 +            short[][] aas = new short[0][];
   1.116 +            short[][][] aaas = new short[0][][];
   1.117 +
   1.118 +            String[] aS = new String[0];
   1.119 +            String[][] aaS = new String[0][];
   1.120 +            String[][][] aaaS = new String[0][][];
   1.121 +        }
   1.122 +    }
   1.123 +}
   1.124 +

mercurial