6937318: jdk7 b86: javah and javah -help is no output for these commands

Wed, 24 Mar 2010 12:18:17 -0700

author
jjg
date
Wed, 24 Mar 2010 12:18:17 -0700
changeset 529
3058880c0b8d
parent 528
dd30de080cb9
child 530
65e422bbb984

6937318: jdk7 b86: javah and javah -help is no output for these commands
Reviewed-by: darcy

src/share/classes/com/sun/tools/javah/JavahTask.java file | annotate | diff | comparison | revisions
test/tools/javah/T6893943.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javah/JavahTask.java	Tue Mar 23 18:05:54 2010 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javah/JavahTask.java	Wed Mar 24 12:18:17 2010 -0700
     1.3 @@ -318,12 +318,6 @@
     1.4      int run(String[] args) {
     1.5          try {
     1.6              handleOptions(args);
     1.7 -            if (classes == null || classes.size() == 0) {
     1.8 -                if (help || version || fullVersion)
     1.9 -                    return 0;
    1.10 -                else
    1.11 -                    return 1;
    1.12 -            }
    1.13              boolean ok = run();
    1.14              return ok ? 0 : 1;
    1.15          } catch (BadArgs e) {
    1.16 @@ -355,7 +349,7 @@
    1.17              fileManager = getDefaultFileManager(diagnosticListener, log);
    1.18  
    1.19          Iterator<String> iter = args.iterator();
    1.20 -        boolean noArgs = !iter.hasNext();
    1.21 +        noArgs = !iter.hasNext();
    1.22  
    1.23          while (iter.hasNext()) {
    1.24              String arg = iter.next();
    1.25 @@ -416,9 +410,9 @@
    1.26  
    1.27          Util util = new Util(log, diagnosticListener);
    1.28  
    1.29 -        if (help) {
    1.30 +        if (noArgs || help) {
    1.31              showHelp();
    1.32 -            return true;
    1.33 +            return help; // treat noArgs as an error for purposes of exit code
    1.34          }
    1.35  
    1.36          if (version || fullVersion) {
    1.37 @@ -636,6 +630,7 @@
    1.38      String usercp;
    1.39      List<String> classes;
    1.40      boolean verbose;
    1.41 +    boolean noArgs;
    1.42      boolean help;
    1.43      boolean trace;
    1.44      boolean version;
     2.1 --- a/test/tools/javah/T6893943.java	Tue Mar 23 18:05:54 2010 -0700
     2.2 +++ b/test/tools/javah/T6893943.java	Wed Mar 24 12:18:17 2010 -0700
     2.3 @@ -23,7 +23,7 @@
     2.4  
     2.5  /*
     2.6   * @test
     2.7 - * @bug 6893943
     2.8 + * @bug 6893943 6937318
     2.9   * @summary exit code from javah with no args is 0
    2.10   */
    2.11  
    2.12 @@ -31,22 +31,32 @@
    2.13  import java.util.*;
    2.14  
    2.15  public class T6893943 {
    2.16 +    static final String[] NO_ARGS = { };
    2.17 +    static final String[] HELP = { "-help" };
    2.18 +    static final String NEWLINE = System.getProperty("line.separator");
    2.19 +
    2.20      public static void main(String... args) throws Exception {
    2.21          new T6893943().run();
    2.22      }
    2.23  
    2.24      void run() throws Exception {
    2.25 -        testSimpleAPI();
    2.26 -        testCommand();
    2.27 +        testSimpleAPI(NO_ARGS, 1);
    2.28 +        testSimpleAPI(HELP, 0);
    2.29 +        testCommand(NO_ARGS, 1);
    2.30 +        testCommand(HELP, 0);
    2.31      }
    2.32  
    2.33 -    void testSimpleAPI() throws Exception {
    2.34 -        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.err));
    2.35 -        int rc = com.sun.tools.javah.Main.run(new String[] { }, pw);
    2.36 -        expect("testSimpleAPI", rc, 1);
    2.37 +    void testSimpleAPI(String[] args, int expect_rc) throws Exception {
    2.38 +        System.err.println("Test simple api: " + Arrays.asList(args));
    2.39 +        StringWriter sw = new StringWriter();
    2.40 +        PrintWriter pw = new PrintWriter(sw);
    2.41 +        int rc = com.sun.tools.javah.Main.run(args, pw);
    2.42 +        pw.close();
    2.43 +        expect("testSimpleAPI", sw.toString(), rc, expect_rc);
    2.44      }
    2.45  
    2.46 -    void testCommand() throws Exception {
    2.47 +    void testCommand(String[] args, int expect_rc) throws Exception {
    2.48 +        System.err.println("Test command: " + Arrays.asList(args));
    2.49          File javaHome = new File(System.getProperty("java.home"));
    2.50          if (javaHome.getName().equals("jre"))
    2.51              javaHome = javaHome.getParentFile();
    2.52 @@ -54,22 +64,32 @@
    2.53          List<String> command = new ArrayList<String>();
    2.54          command.add(new File(new File(javaHome, "bin"), "javah").getPath());
    2.55          command.add("-J-Xbootclasspath:" + System.getProperty("sun.boot.class.path"));
    2.56 +        command.addAll(Arrays.asList(args));
    2.57          //System.err.println("command: " + command);
    2.58  
    2.59          ProcessBuilder pb = new ProcessBuilder(command);
    2.60          pb.redirectErrorStream(true);
    2.61          Process p = pb.start();
    2.62          p.getOutputStream().close();
    2.63 +        StringWriter sw = new StringWriter();
    2.64          String line;
    2.65          BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    2.66          while ((line = in.readLine()) != null)
    2.67 -            System.err.println("javah: " + line);
    2.68 +            sw.write(line + NEWLINE);
    2.69          int rc = p.waitFor();
    2.70 -        expect("testCommand", rc, 1);
    2.71 +        expect("testCommand", sw.toString(), rc, expect_rc);
    2.72      }
    2.73  
    2.74 -    void expect(String name, int actual, int expect) throws Exception {
    2.75 -        if (actual != expect)
    2.76 -            throw new Exception(name + ": unexpected exit: " + actual + ", expected: " + expect);
    2.77 +    void expect(String name, String out, int actual_rc, int expect_rc) throws Exception {
    2.78 +        if (out.isEmpty())
    2.79 +            throw new Exception("No output from javah");
    2.80 +
    2.81 +        if (!out.startsWith("Usage:")) {
    2.82 +            System.err.println(out);
    2.83 +            throw new Exception("Unexpected output from javah");
    2.84 +        }
    2.85 +
    2.86 +        if (actual_rc != expect_rc)
    2.87 +            throw new Exception(name + ": unexpected exit: " + actual_rc + ", expected: " + expect_rc);
    2.88      }
    2.89  }

mercurial