Tue, 18 Feb 2014 19:27:19 +0400
8033180: An inappropriate newline symbol in the help section
Reviewed-by: ksrini
src/share/classes/com/sun/tools/javap/JavapTask.java | file | annotate | diff | comparison | revisions | |
test/tools/javap/T8033180.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javap/JavapTask.java Mon Feb 17 21:51:11 2014 +0400 1.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Tue Feb 18 19:27:19 2014 +0400 1.3 @@ -466,7 +466,7 @@ 1.4 } catch (BadArgs e) { 1.5 reportError(e.key, e.args); 1.6 if (e.showUsage) { 1.7 - log.println(getMessage("main.usage.summary", progname)); 1.8 + printLines(getMessage("main.usage.summary", progname)); 1.9 } 1.10 return EXIT_CMDERR; 1.11 } catch (InternalError e) { 1.12 @@ -882,27 +882,33 @@ 1.13 } 1.14 1.15 private void showHelp() { 1.16 - log.println(getMessage("main.usage", progname)); 1.17 + printLines(getMessage("main.usage", progname)); 1.18 for (Option o: recognizedOptions) { 1.19 String name = o.aliases[0].substring(1); // there must always be at least one name 1.20 if (name.startsWith("X") || name.equals("fullversion") || name.equals("h") || name.equals("verify")) 1.21 continue; 1.22 - log.println(getMessage("main.opt." + name)); 1.23 + printLines(getMessage("main.opt." + name)); 1.24 } 1.25 String[] fmOptions = { "-classpath", "-cp", "-bootclasspath" }; 1.26 for (String o: fmOptions) { 1.27 if (fileManager.isSupportedOption(o) == -1) 1.28 continue; 1.29 String name = o.substring(1); 1.30 - log.println(getMessage("main.opt." + name)); 1.31 + printLines(getMessage("main.opt." + name)); 1.32 } 1.33 1.34 } 1.35 1.36 private void showVersion(boolean full) { 1.37 - log.println(version(full ? "full" : "release")); 1.38 + printLines(version(full ? "full" : "release")); 1.39 } 1.40 1.41 + private void printLines(String msg) { 1.42 + log.println(msg.replace("\n", nl)); 1.43 + } 1.44 + 1.45 + private static final String nl = System.getProperty("line.separator"); 1.46 + 1.47 private static final String versionRBName = "com.sun.tools.javap.resources.version"; 1.48 private static ResourceBundle versionRB; 1.49
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javap/T8033180.java Tue Feb 18 19:27:19 2014 +0400 2.3 @@ -0,0 +1,88 @@ 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 8033180 2.30 + * @summary Bad newline characters 2.31 + */ 2.32 + 2.33 +import java.io.*; 2.34 +import java.util.*; 2.35 + 2.36 +public class T8033180 { 2.37 + 2.38 + public static void main(String... args) throws Exception { 2.39 + new T8033180().run(); 2.40 + } 2.41 + 2.42 + void run() throws Exception { 2.43 + // fast-track this case, because test cannot fail in this case 2.44 + if (lineSep.equals(nl)) 2.45 + return; 2.46 + 2.47 + test("-help"); 2.48 + test("-version"); 2.49 + 2.50 + if (errors > 0) 2.51 + throw new Exception(errors + " errors occurred"); 2.52 + } 2.53 + 2.54 + static final String lineSep = System.getProperty("line.separator"); 2.55 + static final String nl = "\n"; 2.56 + 2.57 + void test(String... opts) throws Exception { 2.58 + System.err.println("test " + Arrays.asList(opts)); 2.59 + List<String> args = new ArrayList<String>(); 2.60 + args.addAll(Arrays.asList(opts)); 2.61 + StringWriter sw = new StringWriter(); 2.62 + PrintWriter pw = new PrintWriter(sw); 2.63 + int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw); 2.64 + pw.close(); 2.65 + String out = sw.toString(); 2.66 + if (rc != 0) 2.67 + throw new Exception("javap failed unexpectedly: rc=" + rc); 2.68 + 2.69 + // remove all valid platform newline sequences 2.70 + String out2 = out.replace(lineSep, ""); 2.71 + 2.72 + // count the remaining simple newline characters 2.73 + int count = 0; 2.74 + int i = out2.indexOf(nl, 0); 2.75 + while (i != -1) { 2.76 + count++; 2.77 + i = out2.indexOf(nl, i + nl.length()); 2.78 + } 2.79 + 2.80 + if (count > 0) 2.81 + error(count + " newline characters found"); 2.82 + } 2.83 + 2.84 + void error(String msg) { 2.85 + System.err.println("Error: " + msg); 2.86 + errors++; 2.87 + } 2.88 + 2.89 + int errors = 0; 2.90 +} 2.91 +