You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by du...@apache.org on 2001/10/23 14:54:39 UTC
cvs commit: xml-axis/java/src/org/apache/axis/encoding DateSerializer.java
dug 01/10/23 05:54:39
Modified: java/src/org/apache/axis/encoding DateSerializer.java
Log:
Remove NPE from DateDeser - found by Mark Roder(mroder@wamnet.com)
Revision Changes Path
1.14 +63 -54 xml-axis/java/src/org/apache/axis/encoding/DateSerializer.java
Index: DateSerializer.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DateSerializer.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- DateSerializer.java 2001/10/18 18:02:13 1.13
+++ DateSerializer.java 2001/10/23 12:54:39 1.14
@@ -84,19 +84,22 @@
Date result;
// validate fixed portion of format
- if (source.length() < 19)
- throw new NumberFormatException("invalid dateTime");
-
- if (source.charAt(4) != '-' || source.charAt(7) != '-' ||
- source.charAt(10) != 'T')
- throw new NumberFormatException("invalid date");
-
- if (source.charAt(13) != ':' || source.charAt(16) != ':')
- throw new NumberFormatException("invalid time");
+ if ( source != null ) {
+ if (source.length() < 19)
+ throw new NumberFormatException("invalid dateTime");
+
+ if (source.charAt(4) != '-' || source.charAt(7) != '-' ||
+ source.charAt(10) != 'T')
+ throw new NumberFormatException("invalid date");
+
+ if (source.charAt(13) != ':' || source.charAt(16) != ':')
+ throw new NumberFormatException("invalid time");
+ }
// convert what we have validated so far
try {
- result=zulu.parse(source.substring(0,19)+".000Z");
+ result = zulu.parse(source == null ? null :
+ (source.substring(0,19)+".000Z") );
} catch (Exception e) {
throw new NumberFormatException(e.toString());
}
@@ -104,58 +107,64 @@
int pos = 19;
// parse optional milliseconds
- if (pos < source.length() && source.charAt(pos)=='.') {
- int milliseconds = 0;
- int start = ++pos;
- while (pos<source.length() && Character.isDigit(source.charAt(pos)))
- pos++;
-
- String decimal=source.substring(start,pos);
- if (decimal.length()==3) {
- milliseconds=Integer.parseInt(decimal);
- } else if (decimal.length() < 3) {
- milliseconds=Integer.parseInt((decimal+"000").substring(0,3));
- } else {
- milliseconds=Integer.parseInt(decimal.substring(0,3));
- if (decimal.charAt(3)>='5') ++milliseconds;
+ if ( source != null ) {
+ if (pos < source.length() && source.charAt(pos)=='.') {
+ int milliseconds = 0;
+ int start = ++pos;
+ while (pos<source.length() &&
+ Character.isDigit(source.charAt(pos)))
+ pos++;
+
+ String decimal=source.substring(start,pos);
+ if (decimal.length()==3) {
+ milliseconds=Integer.parseInt(decimal);
+ } else if (decimal.length() < 3) {
+ milliseconds=Integer.parseInt((decimal+"000")
+ .substring(0,3));
+ } else {
+ milliseconds=Integer.parseInt(decimal.substring(0,3));
+ if (decimal.charAt(3)>='5') ++milliseconds;
+ }
+
+ // add milliseconds to the current result
+ result.setTime(result.getTime()+milliseconds);
}
-
- // add milliseconds to the current result
- result.setTime(result.getTime()+milliseconds);
- }
-
- // parse optional timezone
- if (pos+5 < source.length() &&
- (source.charAt(pos)=='+' || (source.charAt(pos)=='-')))
- {
- if (!Character.isDigit(source.charAt(pos+1)) ||
- !Character.isDigit(source.charAt(pos+2)) ||
- source.charAt(pos+3) != ':' ||
- !Character.isDigit(source.charAt(pos+4)) ||
- !Character.isDigit(source.charAt(pos+5)))
- throw new NumberFormatException("invalid timezone");
-
- int hours = (source.charAt(pos+1)-'0')*10+source.charAt(pos+2)-'0';
- int mins = (source.charAt(pos+4)-'0')*10+source.charAt(pos+5)-'0';
- int milliseconds = (hours*60+mins)*60*1000;
-
- // subtract milliseconds from the current result to obtain GMT
- if (source.charAt(pos)=='+') milliseconds=-milliseconds;
- result.setTime(result.getTime()+milliseconds);
- pos+=6;
+
+ // parse optional timezone
+ if (pos+5 < source.length() &&
+ (source.charAt(pos)=='+' || (source.charAt(pos)=='-')))
+ {
+ if (!Character.isDigit(source.charAt(pos+1)) ||
+ !Character.isDigit(source.charAt(pos+2)) ||
+ source.charAt(pos+3) != ':' ||
+ !Character.isDigit(source.charAt(pos+4)) ||
+ !Character.isDigit(source.charAt(pos+5)))
+ throw new NumberFormatException("invalid timezone");
+
+ int hours = (source.charAt(pos+1)-'0')*10
+ +source.charAt(pos+2)-'0';
+ int mins = (source.charAt(pos+4)-'0')*10
+ +source.charAt(pos+5)-'0';
+ int milliseconds = (hours*60+mins)*60*1000;
+
+ // subtract milliseconds from current result to obtain GMT
+ if (source.charAt(pos)=='+') milliseconds=-milliseconds;
+ result.setTime(result.getTime()+milliseconds);
+ pos+=6;
+ }
+
+ if (pos < source.length() && source.charAt(pos)=='Z') pos++;
+
+ if (pos < source.length())
+ throw new NumberFormatException("unexpected characters");
}
- if (pos < source.length() && source.charAt(pos)=='Z') pos++;
-
- if (pos < source.length())
- throw new NumberFormatException("unexpected characters");
-
return result;
}
}
static public class DateDeserializerFactory implements DeserializerFactory {
- public Deserializer getDeserializer(Class cls) { return new DateDeser(); }
+ public Deserializer getDeserializer(Class cls) {return new DateDeser();}
}
/**