[kaffe] a fix in gjdoc

Nektarios K. Papadopoulos npapadop at inaccessnetworks.com
Fri Apr 16 07:21:01 PDT 2004


Hi Dalibor,


It happened to notice a silly a silly error in gjdoc.

[npapadop at sotos kaffe]$ javadoc -help
java.lang.NullPointerException
    at gnu.classpath.tools.gjdoc.Main.start (Main.java:563)
    at gnu.classpath.tools.gjdoc.Main.main (Main.java:477)

while just typing javadoc was working fine:
[npapadop at sotos kaffe]$ javadoc
ERROR: No packages or classes specified.

USAGE: gjdoc [options] [packagenames] [classnames] [@files]

   -doclet <class>         Doclet class to use for generating output
   -sourcepath <pathlist>  Where to look for ...
...
...

I guess, I am the only one who actually types -help instead of just 
passing no arguments ;-).

The attached patch fix this along with another argument parsing issue 
taged FIXME in the original source.

  I am not following classpath mailing lists or cvs so I post the patch 
here. Sorry if this is a problem.
-------------- next part --------------
Index: tools/gjdoc/javalib/gnu/classpath/tools/gjdoc/Main.java
===================================================================
RCS file: /cvs/kaffe/kaffe/tools/gjdoc/javalib/gnu/classpath/tools/gjdoc/Main.java,v
retrieving revision 1.1
diff -u -r1.1 Main.java
--- tools/gjdoc/javalib/gnu/classpath/tools/gjdoc/Main.java	14 Apr 2004 19:41:12 -0000	1.1
+++ tools/gjdoc/javalib/gnu/classpath/tools/gjdoc/Main.java	16 Apr 2004 14:04:33 -0000
@@ -537,6 +537,9 @@
       List customOptions=new LinkedList();
 
 
+      rootDoc = new RootDocImpl();
+      reporter = rootDoc.getReporter();
+
       //--- Iterate over all options given on the command line
 
       for (Iterator it = arguments.iterator(); it.hasNext(); ) {
@@ -556,29 +559,33 @@
 	 }
 
 	 //--- Otherwise the option is recognized as a standard option.
-	 //         If the option requires more arguments than given on the
-	 //         command line, issue a fatal error
-
-	 else if (!it.hasNext()) {
-	    reporter.printFatal("Missing value for option "+arg+".");
-	 }
-
-	 //--- The option is recognized as standard option, and all
-	 //         required arguments are supplied. Create a new String
+	 //         if all required arguments are supplied. Create a new String
 	 //         array for the option and its arguments, and store it
 	 //         in the options array.
 
-	 //         FIXME: this does not deal well with omitted arguments
-	 //         like such '-sourcepath -private': this would lead
-	 //         to '-private' being silently accepted as an argument
-	 //         to '-sourcepath'.
-
 	 else {
 	    String[] option=new String[optlen];
 	    option[0] = arg;
-	    for (int j=1; j<optlen; ++j)
-	       option[j] = (String)it.next();
-	    options.add(option);
+	    boolean optargs_ok = true;
+	    for (int j=1; j<optlen && optargs_ok; ++j) {
+	 	if (it.hasNext()) {
+	 		option[j] = (String)it.next();
+			if (option[j].startsWith("-")) {
+				optargs_ok = false;
+			}
+		}
+		else {
+			optargs_ok = false;
+		}
+	    }
+	    if (optargs_ok)
+	    	options.add(option);
+	    else {
+	 	//         If the option requires more arguments than given on the
+	 	//         command line, issue a fatal error
+
+	    	reporter.printFatal("Missing value for option "+arg+".");
+	    }
 	 }
       }
 
@@ -587,9 +594,6 @@
       String[][] optionArr=(String[][])options.toArray(new String[options.size()][0]);
 
       //--- Validate all options and issue warnings/errors
-
-      rootDoc = new RootDocImpl();
-      reporter = rootDoc.getReporter();
       
       if (validOptions(optionArr, rootDoc)) {
 


More information about the kaffe mailing list