Simplify code (eliminate conditional check) and avoid NPE warning

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@902955 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2010-01-25 19:40:38 +00:00
parent a6c13a17c0
commit c92f2bcf4c
1 changed files with 3 additions and 7 deletions

View File

@ -312,7 +312,8 @@ public class DateUtils {
throw new IllegalArgumentException("Date and Patterns must not be null"); throw new IllegalArgumentException("Date and Patterns must not be null");
} }
SimpleDateFormat parser = null; SimpleDateFormat parser = new SimpleDateFormat();
parser.setLenient(lenient);
ParsePosition pos = new ParsePosition(0); ParsePosition pos = new ParsePosition(0);
for (int i = 0; i < parsePatterns.length; i++) { for (int i = 0; i < parsePatterns.length; i++) {
@ -323,12 +324,7 @@ public class DateUtils {
pattern = pattern.substring(0, pattern.length() - 1); pattern = pattern.substring(0, pattern.length() - 1);
} }
if (i == 0) { parser.applyPattern(pattern);
parser = new SimpleDateFormat(pattern);
parser.setLenient(lenient);
} else {
parser.applyPattern(pattern); // cannot be null if i != 0
}
pos.setIndex(0); pos.setIndex(0);
String str2 = str; String str2 = str;