1 /* 2 * Copyright (c) 2008, 2025, 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 id=zeroClass 26 * @bug 4870651 6715757 27 * @summary javap should recognize generics, varargs, enum; 28 * javap prints "extends java.lang.Object" 29 * @modules jdk.jdeps/com.sun.tools.javap 30 * @compile Test.java 31 * @run main/othervm -DpreviewClass=false T4870651 32 * @comment runtime in preview or not should not affect javac/javap behavior 33 */ 34 35 /* 36 * @test id=previewClass 37 * @bug 4870651 6715757 38 * @summary javap should recognize generics, varargs, enum; 39 * javap prints "extends java.lang.Object" 40 * @modules jdk.jdeps/com.sun.tools.javap 41 * @compile --enable-preview -source ${jdk.version} -XDforcePreview Test.java 42 * @run main/othervm -DpreviewClass=true T4870651 43 * @comment runtime in preview or not should not affect javac/javap behavior 44 */ 45 46 import java.io.*; 47 48 public class T4870651 { 49 public static void main(String[] args) throws Exception { 50 new T4870651().run(); 51 } 52 53 public void run() throws IOException { 54 verify("Test", 55 "class Test<T extends java.lang.Object, " + 56 "E extends java.lang.Exception & java.lang.Comparable<T>, " + 57 "U extends java.lang.Comparable>", 58 "v1(java.lang.String...)"); 59 60 verify("Test$Enum", 61 Boolean.getBoolean("previewClass") // .65535 instead of .0 62 ? "flags: (0x4030) ACC_FINAL, ACC_IDENTITY, ACC_ENUM" 63 : "flags: (0x4030) ACC_FINAL, ACC_SUPER, ACC_ENUM", 64 "flags: (0x4019) ACC_PUBLIC, ACC_STATIC, ACC_FINAL, ACC_ENUM"); 65 66 if (errors > 0) 67 throw new Error(errors + " found."); 68 } 69 70 String javap(String className) { 71 String testClasses = System.getProperty("test.classes", "."); 72 StringWriter sw = new StringWriter(); 73 PrintWriter out = new PrintWriter(sw); 74 String[] args = { "-classpath", testClasses, "-v", className }; 75 int rc = com.sun.tools.javap.Main.run(args, out); 76 if (rc != 0) 77 throw new Error("javap failed. rc=" + rc); 78 out.close(); 79 String output = sw.toString(); 80 System.out.println("class " + className); 81 System.out.println(output); 82 return output; 83 } 84 85 void verify(String className, String... expects) { 86 String output = javap(className); 87 for (String expect: expects) { 88 if (output.indexOf(expect)< 0) 89 error(expect + " not found"); 90 } 91 } 92 93 void error(String msg) { 94 System.err.println(msg); 95 errors++; 96 } 97 98 int errors; 99 } --- EOF ---