Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T8032819.java
32285 views
/*1* Copyright (c) 2014, 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 803281926* @summary Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options27* @compile -g T8032819.java28* @run main T803281929*/3031import java.io.*;32import java.util.*;3334public class T8032819 {35static class Fields {36int f1;37int f2;38}3940public static void main(String... args) throws Exception {41new T8032819().run();42}4344void run() throws Exception {45Class<?> clazz = Fields.class;46test(clazz);47test(clazz, "-c");48test(clazz, "-l");49test(clazz, "-l", "-c");50test(clazz, "-v");51test(clazz, "-v", "-c");52test(clazz, "-v", "-l");53test(clazz, "-v", "-l", "-c");5455if (errors > 0)56throw new Exception(errors + " errors occurred");57}5859static final String sep = System.getProperty("line.separator");60static final String doubleBlankLine = sep + sep + sep;6162void test(Class<?> clazz, String... opts) throws Exception {63System.err.println("test " + Arrays.asList(opts));64List<String> args = new ArrayList<String>();65args.addAll(Arrays.asList(opts));66args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes")));67args.add(clazz.getName());68StringWriter sw = new StringWriter();69PrintWriter pw = new PrintWriter(sw);70int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);71pw.close();72String out = sw.toString();73if (rc != 0)74throw new Exception("javap failed unexpectedly: rc=" + rc);7576int count = 0;77int i = out.indexOf(doubleBlankLine, 0);78while (i != -1) {79count++;80i = out.indexOf(doubleBlankLine, i + doubleBlankLine.length());81}8283if (count > 0)84error(count + " double blank lines found");85}8687void error(String msg) {88System.err.println("Error: " + msg);89errors++;90}9192int errors = 0;93}94959697