6715753: unknown option error can be a little more helpful

Tue, 08 Jul 2008 17:25:50 -0700

author
jjg
date
Tue, 08 Jul 2008 17:25:50 -0700
changeset 66
df47f7f4c95a
parent 65
0d4aa3c00af5
child 67
1bdd8cea398e

6715753: unknown option error can be a little more helpful
Reviewed-by: ksrini

src/share/classes/com/sun/tools/javap/JavapTask.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javap/resources/javap.properties file | annotate | diff | comparison | revisions
test/tools/javap/T6715753.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javap/JavapTask.java	Tue Jul 08 17:14:22 2008 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javap/JavapTask.java	Tue Jul 08 17:25:50 2008 -0700
     1.3 @@ -298,7 +298,7 @@
     1.4          return new DiagnosticListener<JavaFileObject> () {
     1.5              public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
     1.6                  if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
     1.7 -                    pw.print(getMessage("err.prefix"));
     1.8 +                        pw.print(getMessage("err.prefix"));
     1.9                      pw.print(" ");
    1.10                  }
    1.11                  pw.println(diagnostic.getMessage(null));
    1.12 @@ -331,6 +331,9 @@
    1.13              return ok ? EXIT_OK : EXIT_ERROR;
    1.14          } catch (BadArgs e) {
    1.15              diagnosticListener.report(createDiagnostic(e.key, e.args));
    1.16 +            if (e.showUsage) {
    1.17 +                log.println(getMessage("main.usage.summary", progname));
    1.18 +            }
    1.19              return EXIT_CMDERR;
    1.20          } catch (InternalError e) {
    1.21              Object[] e_args;
     2.1 --- a/src/share/classes/com/sun/tools/javap/resources/javap.properties	Tue Jul 08 17:14:22 2008 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javap/resources/javap.properties	Tue Jul 08 17:25:50 2008 -0700
     2.3 @@ -16,6 +16,10 @@
     2.4  err.verify.not.supported=-verify not supported
     2.5  err.Xold.not.supported.here=-Xold must be given as the first option
     2.6  
     2.7 +main.usage.summary=\
     2.8 +Usage: {0} <options> <classes>\n\
     2.9 +use -help for a list of possible options
    2.10 +
    2.11  main.usage=\
    2.12  Usage: {0} <options> <classes>\n\
    2.13  where possible options include:
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javap/T6715753.java	Tue Jul 08 17:25:50 2008 -0700
     3.3 @@ -0,0 +1,50 @@
     3.4 +/*
     3.5 + * Copyright 2008 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.24 + * have any questions.
    3.25 + */
    3.26 +
    3.27 +import java.io.*;
    3.28 +
    3.29 +/*
    3.30 + * @test
    3.31 + * @bug 6715753
    3.32 + * @summary Use javap to inquire about a specific inner class
    3.33 + */
    3.34 +
    3.35 +public class T6715753 {
    3.36 +    public static void main(String... args) throws Exception {
    3.37 +        new T6715753().run();
    3.38 +    }
    3.39 +
    3.40 +    void run() throws Exception {
    3.41 +        StringWriter sw = new StringWriter();
    3.42 +        PrintWriter pw = new PrintWriter(sw);
    3.43 +        String[] args = { "-notAnOption" };
    3.44 +        int rc = com.sun.tools.javap.Main.run(args, pw);
    3.45 +        String log = sw.toString();
    3.46 +        if (rc == 0
    3.47 +            || log.indexOf("-notAnOption") == -1
    3.48 +            || log.indexOf("javap") == -1) { // locale-independent indication of usage message
    3.49 +            System.err.println("rc: " + rc + ", log=\n" + log);
    3.50 +            throw new Exception("test failed");
    3.51 +        }
    3.52 +    }
    3.53 +}
    3.54 \ No newline at end of file

mercurial