1 /*
   2  * Copyright (c) 2009, 2015, 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  */
  23 
  24 /*
  25  * @test
  26  * @bug 6887895
  27  * @summary CONSTANT_Class_info getBaseName does not handle arrays of primitives correctly
  28  * @modules jdk.jdeps/com.sun.tools.classfile
  29  */
  30 
  31 import java.io.*;
  32 import java.net.*;
  33 import java.util.*;
  34 import com.sun.tools.classfile.*;
  35 import com.sun.tools.classfile.ConstantPool.*;
  36 
  37 public class T6887895 {
  38     public static void main(String[] args) throws Exception {
  39         new T6887895().run();
  40     }
  41 
  42     void run() throws Exception {
  43         Set<String> found = new TreeSet<String>();
  44 
  45         ClassFile cf = getClassFile("T6887895$Test.class");
  46         for (CPInfo cpInfo: cf.constant_pool.entries()) {
  47             if (cpInfo instanceof CONSTANT_Class_info) {
  48                 CONSTANT_Class_info info = (CONSTANT_Class_info) cpInfo;
  49                 String name = info.getName();
  50                 String baseName = info.getBaseName();
  51                 System.out.println("found: " + name + " " + baseName);
  52                 if (baseName != null)
  53                     found.add(baseName);
  54             }
  55         }
  56 
  57         String[] expectNames = {
  58             "java/lang/Object",
  59             "java/lang/String",
  60             "T6887895",
  61             "T6887895$Test"
  62         };
  63 
  64         Set<String> expect = new TreeSet<String>(Arrays.asList(expectNames));
  65         if (!found.equals(expect)) {
  66             System.err.println("found: " + found);
  67             System.err.println("expect: " + expect);
  68             throw new Exception("unexpected values found");
  69         }
  70     }
  71 
  72     ClassFile getClassFile(String name) throws IOException, ConstantPoolException {
  73         URL url = getClass().getResource(name);
  74         InputStream in = url.openStream();
  75         try {
  76             return ClassFile.read(in);
  77         } finally {
  78             in.close();
  79         }
  80     }
  81 
  82     class Test {
  83         void m() {
  84             boolean[] az = new boolean[0];
  85             boolean[][] aaz = new boolean[0][];
  86             boolean[][][] aaaz = new boolean[0][][];
  87 
  88             byte[] ab = new byte[0];
  89             byte[][] aab = new byte[0][];
  90             byte[][][] aaab = new byte[0][][];
  91 
  92             char[] ac = new char[0];
  93             char[][] aac = new char[0][];
  94             char[][][] aaac = new char[0][][];
  95 
  96             double[] ad = new double[0];
  97             double[][] aad = new double[0][];
  98             double[][][] aaad = new double[0][][];
  99 
 100             float[] af = new float[0];
 101             float[][] aaf = new float[0][];
 102             float[][][] aaaf = new float[0][][];
 103 
 104             int[] ai = new int[0];
 105             int[][] aai = new int[0][];
 106             int[][][] aaai = new int[0][][];
 107 
 108             long[] al = new long[0];
 109             long[][] aal = new long[0][];
 110             long[][][] aaal = new long[0][][];
 111 
 112             short[] as = new short[0];
 113             short[][] aas = new short[0][];
 114             short[][][] aaas = new short[0][][];
 115 
 116             String[] aS = new String[0];
 117             String[][] aaS = new String[0][];
 118             String[][][] aaaS = new String[0][][];
 119         }
 120     }
 121 }
 122