File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
main/java/org/springframework/batch/core
test/java/org/springframework/batch/core Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2006-2018 the original author or authors.
2
+ * Copyright 2006-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import java .util .Date ;
21
21
import java .util .LinkedHashMap ;
22
22
import java .util .Map ;
23
+ import java .util .Objects ;
23
24
import java .util .Properties ;
24
25
25
26
import org .springframework .lang .Nullable ;
38
39
* @author Lucas Ward
39
40
* @author Michael Minella
40
41
* @author Mahmoud Ben Hassine
42
+ * @author Taeik Lim
41
43
* @since 1.0
42
44
*/
43
45
@ SuppressWarnings ("serial" )
@@ -269,8 +271,8 @@ public Properties toProperties() {
269
271
Properties props = new Properties ();
270
272
271
273
for (Map .Entry <String , JobParameter > param : parameters .entrySet ()) {
272
- if (param .getValue () != null ) {
273
- props .put (param .getKey (), param .getValue ().toString ());
274
+ if (param .getValue () != null ) {
275
+ props .put (param .getKey (), Objects . toString ( param .getValue ().toString (), "" ));
274
276
}
275
277
}
276
278
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2008-2018 the original author or authors.
2
+ * Copyright 2008-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
25
25
import java .util .HashMap ;
26
26
import java .util .Map ;
27
27
import java .util .Map .Entry ;
28
+ import java .util .Properties ;
28
29
29
30
import org .junit .Before ;
30
31
import org .junit .Test ;
35
36
* @author Dave Syer
36
37
* @author Michael Minella
37
38
* @author Mahmoud Ben Hassine
39
+ * @author Taeik Lim
38
40
*
39
41
*/
40
42
public class JobParametersTests {
@@ -228,4 +230,15 @@ public void testDoubleReturnsNullWhenKeyDoesntExit(){
228
230
public void testDateReturnsNullWhenKeyDoesntExit (){
229
231
assertNull (new JobParameters ().getDate ("keythatdoesntexist" ));
230
232
}
233
+
234
+ @ Test
235
+ public void testToPropertiesWithNullValue () {
236
+ Map <String , JobParameter > parameterMap = new HashMap <>();
237
+ Long value = null ;
238
+ parameterMap .put ("nullkey" , new JobParameter (value ));
239
+ JobParameters jobParameters = new JobParameters (parameterMap );
240
+
241
+ Properties properties = jobParameters .toProperties ();
242
+ assertEquals ("" , properties .get ("nullkey" ));
243
+ }
231
244
}
You can’t perform that action at this time.
0 commit comments