Mon, 19 Jun 2017 14:51:25 -0700
Added tag jdk8u151-b02 for changeset 732e1bab2660
1 /*
2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
24 /*
25 * @test
26 * @bug 6887895
27 * @summary CONSTANT_Class_info getBaseName does not handle arrays of primitives correctly
28 */
30 import java.io.*;
31 import java.net.*;
32 import java.util.*;
33 import com.sun.tools.classfile.*;
34 import com.sun.tools.classfile.ConstantPool.*;
36 public class T6887895 {
37 public static void main(String[] args) throws Exception {
38 new T6887895().run();
39 }
41 void run() throws Exception {
42 Set<String> found = new TreeSet<String>();
44 ClassFile cf = getClassFile("T6887895$Test.class");
45 for (CPInfo cpInfo: cf.constant_pool.entries()) {
46 if (cpInfo instanceof CONSTANT_Class_info) {
47 CONSTANT_Class_info info = (CONSTANT_Class_info) cpInfo;
48 String name = info.getName();
49 String baseName = info.getBaseName();
50 System.out.println("found: " + name + " " + baseName);
51 if (baseName != null)
52 found.add(baseName);
53 }
54 }
56 String[] expectNames = {
57 "java/lang/Object",
58 "java/lang/String",
59 "T6887895",
60 "T6887895$Test"
61 };
63 Set<String> expect = new TreeSet<String>(Arrays.asList(expectNames));
64 if (!found.equals(expect)) {
65 System.err.println("found: " + found);
66 System.err.println("expect: " + expect);
67 throw new Exception("unexpected values found");
68 }
69 }
71 ClassFile getClassFile(String name) throws IOException, ConstantPoolException {
72 URL url = getClass().getResource(name);
73 InputStream in = url.openStream();
74 try {
75 return ClassFile.read(in);
76 } finally {
77 in.close();
78 }
79 }
81 class Test {
82 void m() {
83 boolean[] az = new boolean[0];
84 boolean[][] aaz = new boolean[0][];
85 boolean[][][] aaaz = new boolean[0][][];
87 byte[] ab = new byte[0];
88 byte[][] aab = new byte[0][];
89 byte[][][] aaab = new byte[0][][];
91 char[] ac = new char[0];
92 char[][] aac = new char[0][];
93 char[][][] aaac = new char[0][][];
95 double[] ad = new double[0];
96 double[][] aad = new double[0][];
97 double[][][] aaad = new double[0][][];
99 float[] af = new float[0];
100 float[][] aaf = new float[0][];
101 float[][][] aaaf = new float[0][][];
103 int[] ai = new int[0];
104 int[][] aai = new int[0][];
105 int[][][] aaai = new int[0][][];
107 long[] al = new long[0];
108 long[][] aal = new long[0][];
109 long[][][] aaal = new long[0][][];
111 short[] as = new short[0];
112 short[][] aas = new short[0][];
113 short[][][] aaas = new short[0][][];
115 String[] aS = new String[0];
116 String[][] aaS = new String[0][];
117 String[][][] aaaS = new String[0][][];
118 }
119 }
120 }