Path: blob/master/test/langtools/tools/javap/T4975569.java
41144 views
/*1* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 4975569 6622215 803486126* @summary javap doesn't print new flag bits27* @modules jdk.jdeps/com.sun.tools.javap28*/2930import java.io.*;31import java.util.*;32import java.util.regex.Matcher;33import java.util.regex.Pattern;3435public class T4975569 {36private static final String NEW_LINE = System.getProperty("line.separator");37private static final String TEST_CLASSES = System.getProperty("test.classes", ".");3839public static void main(String... args) {40new T4975569().run();41}4243void run() {44verify(Anno.class.getName(), "flags: \\(0x2600\\) ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION");45verify(E.class.getName(), "flags: \\(0x4030\\) ACC_FINAL, ACC_SUPER, ACC_ENUM");46verify(S.class.getName(), "flags: \\(0x1040\\) ACC_BRIDGE, ACC_SYNTHETIC",47"InnerClasses:\n static [# =\\w]+; +// ");48verify(V.class.getName(), "void m\\(java.lang.String...\\)",49"flags: \\(0x0080\\) ACC_VARARGS");50verify(Prot.class.getName(), "InnerClasses:\n protected [# =\\w]+; +// ");51verify(Priv.class.getName(), new String[]{"-p"},52"InnerClasses:\n private [# =\\w]+; +// ");5354if (errors > 0)55throw new Error(errors + " found.");56}5758void verify(String className, String[] flags, String... expects) {59String output = javap(className, Arrays.asList(flags));60for (String expect: expects) {61Pattern expectPattern = Pattern.compile(expect);62Matcher matcher = expectPattern.matcher(output);63if (!matcher.find()) {64error(expect + " not found");65}66}67}6869void verify(String className, String... expects) {70verify(className, new String[0], expects);71}7273int errors;74void error(String msg) {75System.err.println(msg.replace("\n", NEW_LINE));76errors++;77}7879String javap(String className, List<String> flags) {80StringWriter sw = new StringWriter();81PrintWriter out = new PrintWriter(sw);82List<String> args = new ArrayList<>(flags);83args.addAll(Arrays.asList("-v", "-classpath", TEST_CLASSES, className));84int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), out);85out.close();86String output = sw.toString();87System.err.println("class " + className);88System.err.println(output);8990if (rc != 0)91throw new Error("javap failed. rc=" + rc);92return output.replaceAll(NEW_LINE, "\n");93}9495List x() { return null; }9697class V { void m(String... args) { } }98enum E { e }99@interface Anno { }100static class S extends T4975569 {101ArrayList x() { return null; }102}103104protected class Prot { }105private class Priv { int i; }106}107108109110