8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options

Sat, 15 Feb 2014 22:23:44 +0400

author
kizune
date
Sat, 15 Feb 2014 22:23:44 +0400
changeset 2277
77942ba5797f
parent 2276
ec78aef148eb
child 2278
8af239a7b0b7

8032819: Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
Reviewed-by: ksrini

src/share/classes/com/sun/tools/javap/ClassWriter.java file | annotate | diff | comparison | revisions
test/tools/javap/T8032819.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javap/ClassWriter.java	Fri Feb 14 14:21:19 2014 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javap/ClassWriter.java	Sat Feb 15 22:23:44 2014 +0400
     1.3 @@ -385,6 +385,8 @@
     1.4  
     1.5          indent(+1);
     1.6  
     1.7 +        boolean showBlank = false;
     1.8 +
     1.9          if (options.showDescriptors)
    1.10              println("descriptor: " + getValue(f.descriptor));
    1.11  
    1.12 @@ -394,12 +396,12 @@
    1.13          if (options.showAllAttrs) {
    1.14              for (Attribute attr: f.attributes)
    1.15                  attrWriter.write(f, attr, constant_pool);
    1.16 -            println();
    1.17 +            showBlank = true;
    1.18          }
    1.19  
    1.20          indent(-1);
    1.21  
    1.22 -        if (options.showDisassembled || options.showLineAndLocalVariableTables)
    1.23 +        if (showBlank || options.showDisassembled || options.showLineAndLocalVariableTables)
    1.24              println();
    1.25      }
    1.26  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javap/T8032819.java	Sat Feb 15 22:23:44 2014 +0400
     2.3 @@ -0,0 +1,95 @@
     2.4 +/*
     2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug 8032819
    2.30 + * @summary Extra empty line between field declarations for the "-v -c" and "-v -l" combination of options
    2.31 + * @compile -g T8032819.java
    2.32 + * @run main T8032819
    2.33 + */
    2.34 +
    2.35 +import java.io.*;
    2.36 +import java.util.*;
    2.37 +
    2.38 +public class T8032819 {
    2.39 +    static class Fields {
    2.40 +        int f1;
    2.41 +        int f2;
    2.42 +    }
    2.43 +
    2.44 +    public static void main(String... args) throws Exception {
    2.45 +        new T8032819().run();
    2.46 +    }
    2.47 +
    2.48 +    void run() throws Exception {
    2.49 +        Class<?> clazz = Fields.class;
    2.50 +        test(clazz);
    2.51 +        test(clazz, "-c");
    2.52 +        test(clazz, "-l");
    2.53 +        test(clazz, "-l", "-c");
    2.54 +        test(clazz, "-v");
    2.55 +        test(clazz, "-v", "-c");
    2.56 +        test(clazz, "-v", "-l");
    2.57 +        test(clazz, "-v", "-l", "-c");
    2.58 +
    2.59 +        if (errors > 0)
    2.60 +            throw new Exception(errors + " errors occurred");
    2.61 +    }
    2.62 +
    2.63 +    static final String sep = System.getProperty("line.separator");
    2.64 +    static final String doubleBlankLine = sep + sep + sep;
    2.65 +
    2.66 +    void test(Class<?> clazz, String... opts) throws Exception {
    2.67 +        System.err.println("test " + Arrays.asList(opts));
    2.68 +        List<String> args = new ArrayList<String>();
    2.69 +        args.addAll(Arrays.asList(opts));
    2.70 +        args.addAll(Arrays.asList("-classpath", System.getProperty("test.classes")));
    2.71 +        args.add(clazz.getName());
    2.72 +        StringWriter sw = new StringWriter();
    2.73 +        PrintWriter pw = new PrintWriter(sw);
    2.74 +        int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);
    2.75 +        pw.close();
    2.76 +        String out = sw.toString();
    2.77 +        if (rc != 0)
    2.78 +            throw new Exception("javap failed unexpectedly: rc=" + rc);
    2.79 +
    2.80 +        int count = 0;
    2.81 +        int i = out.indexOf(doubleBlankLine, 0);
    2.82 +        while (i != -1) {
    2.83 +            count++;
    2.84 +            i = out.indexOf(doubleBlankLine, i + doubleBlankLine.length());
    2.85 +        }
    2.86 +
    2.87 +        if (count > 0)
    2.88 +            error(count + " double blank lines found");
    2.89 +    }
    2.90 +
    2.91 +    void error(String msg) {
    2.92 +        System.err.println("Error: " + msg);
    2.93 +        errors++;
    2.94 +    }
    2.95 +
    2.96 +    int errors = 0;
    2.97 +}
    2.98 +

mercurial