Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T7004698.java
32285 views
/*1* Copyright (c) 2010, 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*/2829import java.io.*;30import java.util.*;31import java.util.regex.*;3233public class T7004698 {34public static void main(String... args) throws Exception {35new T7004698().run();36}3738void run() throws Exception {39File srcDir = new File(System.getProperty("test.src"));40File srcFile = new File(srcDir, T7004698.class.getSimpleName() + ".java");41File classesDir = new File(".");42compile("-Xjcov", "-d", classesDir.getPath(), srcFile.getPath());4344File classFile = new File(classesDir, T7004698.class.getSimpleName() + ".class");45String out = javap("-v", classFile.getPath());4647Pattern attrBody = Pattern.compile("[0-9a-f, ]+//[-0-9a-z:, ]+");48Pattern endOfAttr = Pattern.compile("(^$|[A-Z][A-Za-z0-9_]+:.*|})");49boolean inAttr = false;50int count = 0;51int errors = 0;52for (String line: out.split(System.getProperty("line.separator"))) {53line = line.trim();54if (line.equals("CharacterRangeTable:")) {55inAttr = true;56count++;57} else if (inAttr) {58if (endOfAttr.matcher(line).matches()) {59inAttr = false;60} else if (!attrBody.matcher(line).matches()) {61System.err.println("unexpected line found: " + line);62errors++;63}64}65}66if (count == 0)67throw new Exception("no attribute instances found");6869if (errors > 0)70throw new Exception(errors + " errors found");71}7273void compile(String... args) throws Exception {74StringWriter sw = new StringWriter();75PrintWriter pw = new PrintWriter(sw);76int rc = com.sun.tools.javac.Main.compile(args, pw);77pw.close();78String out = sw.toString();79if (!out.isEmpty())80System.err.println(out);81if (rc != 0)82throw new Exception("javac failed unexpectedly; rc=" + rc);83}8485String javap(String... args) throws Exception {86StringWriter sw = new StringWriter();87PrintWriter pw = new PrintWriter(sw);88int rc = com.sun.tools.javap.Main.run(args, pw);89pw.close();90String out = sw.toString();91if (!out.isEmpty())92System.err.println(out);93if (rc != 0)94throw new Exception("javap failed unexpectedly; rc=" + rc);95return out;96}97}9899100