RESOLVED - BATCH-1853: If the JobParameters is asked for a Date value that doesn't exist, it will now return null rather than throwing NPE
This commit is contained in:
@@ -148,7 +148,7 @@ public class JobParameters implements Serializable {
|
||||
* @return The <code>java.util.Date</code> value
|
||||
*/
|
||||
public Date getDate(String key){
|
||||
return (Date)parameters.get(key).getValue();
|
||||
return this.getDate(key,null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +162,7 @@ public class JobParameters implements Serializable {
|
||||
*/
|
||||
public Date getDate(String key, Date defaultValue){
|
||||
if(parameters.containsKey(key)){
|
||||
return getDate(key);
|
||||
return (Date)parameters.get(key).getValue();
|
||||
}
|
||||
else{
|
||||
return defaultValue;
|
||||
|
||||
@@ -191,4 +191,24 @@ public class JobParametersTests {
|
||||
|
||||
assertEquals(params, SerializationUtils.deserialize(serialized));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongReturns0WhenKeyDoesntExit(){
|
||||
assertEquals(0L,new JobParameters().getLong("keythatdoesntexist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringReturnsNullWhenKeyDoesntExit(){
|
||||
assertNull(new JobParameters().getString("keythatdoesntexist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleReturns0WhenKeyDoesntExit(){
|
||||
assertEquals(0.0,new JobParameters().getLong("keythatdoesntexist"), 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateReturnsNullWhenKeyDoesntExit(){
|
||||
assertNull(new JobParameters().getDate("keythatdoesntexist"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user