1 /* 2 * Copyright (c) 2019, 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 8222634 27 * @summary Check array creation with value classes 28 * @modules jdk.compiler/com.sun.tools.javac.util jdk.jdeps/com.sun.tools.javap 29 * @modules jdk.compiler 30 * @compile --enable-preview -source ${jdk.version} ArrayCreationWithQuestion.java 31 * @run main/othervm --enable-preview ArrayCreationWithQuestion 32 */ 33 34 import java.io.PrintWriter; 35 import java.io.StringWriter; 36 import java.nio.file.Paths; 37 38 public class ArrayCreationWithQuestion { 39 40 static value class VT { 41 VT[] a1; 42 VT[] a2; 43 44 VT() { 45 a1 = new VT[42]; 46 a2 = new VT[42]; 47 } 48 } 49 50 public static void main(String[] args) { 51 new ArrayCreationWithQuestion().run(); 52 } 53 54 void run() { 55 String [] params = new String [] { "-v", 56 Paths.get(System.getProperty("test.classes"), 57 "ArrayCreationWithQuestion$VT.class").toString() }; 58 runCheck(params, new String [] { 59 " 3: anewarray #1 // class ArrayCreationWithQuestion$VT", 60 " 12: anewarray #1 // class ArrayCreationWithQuestion$VT", 61 }); 62 63 } 64 65 void runCheck(String [] params, String [] expectedOut) { 66 StringWriter s; 67 String out; 68 69 try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { 70 com.sun.tools.javap.Main.run(params, pw); 71 out = s.toString(); 72 } 73 int errors = 0; 74 for (String eo: expectedOut) { 75 if (!out.contains(eo)) { 76 System.err.println("Match not found for string: " + eo); 77 errors++; 78 } 79 } 80 if (errors > 0) { 81 throw new AssertionError("Unexpected javap output: " + out); 82 } 83 } 84 }