Tue, 11 Feb 2014 23:30:36 +0400
8033711: An exception is thrown if using the "-classpath" option with no arguments
Reviewed-by: ksrini
1.1 --- a/src/share/classes/com/sun/tools/javap/JavapTask.java Tue Feb 11 19:05:50 2014 +0400 1.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java Tue Feb 11 23:30:36 2014 +0400 1.3 @@ -561,8 +561,12 @@ 1.4 } 1.5 } 1.6 1.7 - if (fileManager.handleOption(name, rest)) 1.8 - return; 1.9 + try { 1.10 + if (fileManager.handleOption(name, rest)) 1.11 + return; 1.12 + } catch (IllegalArgumentException e) { 1.13 + throw new BadArgs("err.invalid.use.of.option", name).showUsage(true); 1.14 + } 1.15 1.16 throw new BadArgs("err.unknown.option", name).showUsage(true); 1.17 }
2.1 --- a/src/share/classes/com/sun/tools/javap/resources/javap.properties Tue Feb 11 19:05:50 2014 +0400 2.2 +++ b/src/share/classes/com/sun/tools/javap/resources/javap.properties Tue Feb 11 23:30:36 2014 +0400 2.3 @@ -14,6 +14,7 @@ 2.4 err.missing.arg=no value given for {0} 2.5 err.no.classes.specified=no classes specified 2.6 err.not.standard.file.manager=can only specify class files when using a standard file manager 2.7 +err.invalid.use.of.option=invalid use of option: {0} 2.8 err.unknown.option=unknown option: {0} 2.9 err.verify.not.supported=-verify not supported 2.10 err.no.SourceFile.attribute=no SourceFile attribute
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/test/tools/javap/T8033711.java Tue Feb 11 23:30:36 2014 +0400 3.3 @@ -0,0 +1,55 @@ 3.4 +/* 3.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 + * 3.8 + * This code is free software; you can redistribute it and/or modify it 3.9 + * under the terms of the GNU General Public License version 2 only, as 3.10 + * published by the Free Software Foundation. 3.11 + * 3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.15 + * version 2 for more details (a copy is included in the LICENSE file that 3.16 + * accompanied this code). 3.17 + * 3.18 + * You should have received a copy of the GNU General Public License version 3.19 + * 2 along with this work; if not, write to the Free Software Foundation, 3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.21 + * 3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.23 + * or visit www.oracle.com if you need additional information or have any 3.24 + * questions. 3.25 + */ 3.26 + 3.27 +/* 3.28 + * @test 3.29 + * @bug 8033711 3.30 + * @summary An exception is thrown if using the "-classpath" option with no arguments 3.31 + */ 3.32 + 3.33 + 3.34 +import java.io.*; 3.35 + 3.36 +public class T8033711 { 3.37 + public static void main(String[] args) throws Exception { 3.38 + new T8033711().run(); 3.39 + } 3.40 + 3.41 + public void run() throws Exception { 3.42 + String out = javap("-classpath"); 3.43 + if (out.contains("IllegalArgumentException")) 3.44 + throw new Exception("exception found in javap output"); 3.45 + if (!out.contains("Error: invalid use of option")) 3.46 + throw new Exception("expected error message not found in javap output"); 3.47 + } 3.48 + 3.49 + String javap(String... args) { 3.50 + StringWriter sw = new StringWriter(); 3.51 + PrintWriter out = new PrintWriter(sw); 3.52 + int rc = com.sun.tools.javap.Main.run(args, out); 3.53 + out.close(); 3.54 + System.out.println(sw.toString()); 3.55 + System.out.println("javap exited, rc=" + rc); 3.56 + return sw.toString(); 3.57 + } 3.58 +}