Path: blob/master/test/langtools/tools/javap/T7004698.java
41144 views
/*1* Copyright (c) 2010, 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 700469826* @summary javap does not output CharacterRangeTable attributes correctly27* @modules jdk.jdeps/com.sun.tools.javap28*/2930import java.io.*;31import java.util.*;32import java.util.regex.*;3334public class T7004698 {35public static void main(String... args) throws Exception {36new T7004698().run();37}3839void run() throws Exception {40File srcDir = new File(System.getProperty("test.src"));41File srcFile = new File(srcDir, T7004698.class.getSimpleName() + ".java");42File classesDir = new File(".");43compile("-Xjcov",44"--add-modules", "jdk.jdeps",45"--add-exports", "jdk.jdeps/com.sun.tools.javap=ALL-UNNAMED",46"-d", classesDir.getPath(),47srcFile.getPath());4849File classFile = new File(classesDir, T7004698.class.getSimpleName() + ".class");50String out = javap("-v", classFile.getPath());5152Pattern attrBody = Pattern.compile("[0-9a-f, ]+//[-0-9a-z:, ]+");53Pattern endOfAttr = Pattern.compile("(^$|[A-Z][A-Za-z0-9_]+:.*|})");54boolean inAttr = false;55int count = 0;56int errors = 0;57for (String line: out.split(System.getProperty("line.separator"))) {58line = line.trim();59if (line.equals("CharacterRangeTable:")) {60inAttr = true;61count++;62} else if (inAttr) {63if (endOfAttr.matcher(line).matches()) {64inAttr = false;65} else if (!attrBody.matcher(line).matches()) {66System.err.println("unexpected line found: " + line);67errors++;68}69}70}71if (count == 0)72throw new Exception("no attribute instances found");7374if (errors > 0)75throw new Exception(errors + " errors found");76}7778void compile(String... args) throws Exception {79StringWriter sw = new StringWriter();80PrintWriter pw = new PrintWriter(sw);81int rc = com.sun.tools.javac.Main.compile(args, pw);82pw.close();83String out = sw.toString();84if (!out.isEmpty())85System.err.println(out);86if (rc != 0)87throw new Exception("javac failed unexpectedly; rc=" + rc);88}8990String javap(String... args) throws Exception {91StringWriter sw = new StringWriter();92PrintWriter pw = new PrintWriter(sw);93int rc = com.sun.tools.javap.Main.run(args, pw);94pw.close();95String out = sw.toString();96if (!out.isEmpty())97System.err.println(out);98if (rc != 0)99throw new Exception("javap failed unexpectedly; rc=" + rc);100return out;101}102}103104105