Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4966555

Provision to suppress usage mesg when dealing with the err code programmatically

XMLWordPrintable

    • generic
    • solaris_9

      Customer description:

      It's good to see RFE: 4658707 addressed in 1.4.2.

      However, one thing that might really be a bug is
      that when you do not pass in java classes to be compiled by the compile method,
      it spits out the usage message and there's no way to supress it that I saw.

      import com.sun.tools.javac.Main;

      public class TestJavac {
        public static void main(String[] Rgs) {
          String[] goodargs = { "-d", ".", "foo.java" };
          String[] badargs = { "-d", "." };
          Main compiler = new Main();
          int badout = compiler.compile(badargs);
         System.out.println("bad out: " + badout);
        }
      }

      java -classpath /home/ckprasad/j2sdk1.4.2_01/lib/tools.jar:. TestJavac
      javac: no source files
      Usage: javac <options> <source files>
      where possible options include:
        -g Generate all debugging info
        -g:none Generate no debugging info
        -g:{lines,vars,source} Generate only some debugging info
        -nowarn Generate no warnings
        -verbose Output messages about what the compiler is doing
        -deprecation Output source locations where deprecated APIs are used
        -classpath <path> Specify where to find user class files
        -sourcepath <path> Specify where to find input source files
        -bootclasspath <path> Override location of bootstrap class files
        -extdirs <dirs> Override location of installed extensions
        -d <directory> Specify where to place generated class files
        -encoding <encoding> Specify character encoding used by source files
        -source <release> Provide source compatibility with specified release
        -target <release> Generate class files for specific VM version
        -help Print a synopsis of standard options

      bad out: 2

      when you pass in no files, you get a usage message and error
      code 2.

      If you want to deal with the error code programmatically, you
      might not want to automatically display the usage message.

      I don't know how you fix this without making the compile method
      throw an exception with the usage message as its message, instead of
      returning a code...but either way, it would be nice to just get a return
      value, and not HAVE to see the usage message.

            jjg Jonathan Gibbons
            cprasadsunw Ck Prasad (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: