Update of /cvsroot/commonjava/commonjava-projects/commonjava-console/src/java/org/commonjava/console
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13817/src/java/org/commonjava/console
Modified Files:
CommandLine.java
Log Message:
o Fixed a NPE when the long-name is specified and no value is supplied.
o Added debug statements for the parseArgs() functionality.
Index: CommandLine.java
===================================================================
RCS file: /cvsroot/commonjava/commonjava-projects/commonjava-console/src/java/org/commonjava/console/CommandLine.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- CommandLine.java 15 Apr 2004 15:23:54 -0000 1.3
+++ CommandLine.java 28 Jun 2004 04:12:54 -0000 1.4
@@ -112,7 +112,7 @@
String key = args[i].substring(2, ((eqPos < 0)?(args[i].length()):(eqPos)));
String val = ((eqPos < 0)?(null):(args[i].substring(eqPos+1)));
- if(val.startsWith("\"")){
+ if(val != null && val.startsWith("\"")){
StringBuffer buf = new StringBuffer(val.substring(1));
i++;
for(; i<args.length; i++){
@@ -131,6 +131,9 @@
val = buf.toString();
}
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Adding long option: " + key + " with value: " + val);
+ }
vals.put(key, val);
}
else if(args[i].charAt(0) == '-'){
@@ -141,6 +144,9 @@
char c = args[i].charAt(j);
Character shortName = new Character(c);
if(j+1 < argLen){
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Adding short option: " + shortName + " with null value.");
+ }
vals.put(shortName, null);
}
else{
@@ -166,19 +172,31 @@
val = buf.toString();
}
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Adding short option: " + shortName + " with value: " + val);
+ }
vals.put(shortName, val);
}
else{
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Adding short option: " + shortName + " with null value.");
+ }
vals.put(shortName, null);
}
}
}
}
else{
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Adding command argument: " + args[i]);
+ }
nonOptions.add(args[i]);
}
}
else{
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Adding command argument: " + args[i]);
+ }
nonOptions.add(args[i]);
}
}
|