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 11/*
2- * Copyright 2006-2018 the original author or authors.
2+ * Copyright 2006-2021 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2020import java .util .Date ;
2121import java .util .LinkedHashMap ;
2222import java .util .Map ;
23+ import java .util .Objects ;
2324import java .util .Properties ;
2425
2526import org .springframework .lang .Nullable ;
3839 * @author Lucas Ward
3940 * @author Michael Minella
4041 * @author Mahmoud Ben Hassine
42+ * @author Taeik Lim
4143 * @since 1.0
4244 */
4345@ SuppressWarnings ("serial" )
@@ -269,8 +271,8 @@ public Properties toProperties() {
269271 Properties props = new Properties ();
270272
271273 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 (), "" ));
274276 }
275277 }
276278
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2008-2018 the original author or authors.
2+ * Copyright 2008-2021 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2525import java .util .HashMap ;
2626import java .util .Map ;
2727import java .util .Map .Entry ;
28+ import java .util .Properties ;
2829
2930import org .junit .Before ;
3031import org .junit .Test ;
3536 * @author Dave Syer
3637 * @author Michael Minella
3738 * @author Mahmoud Ben Hassine
39+ * @author Taeik Lim
3840 *
3941 */
4042public class JobParametersTests {
@@ -228,4 +230,15 @@ public void testDoubleReturnsNullWhenKeyDoesntExit(){
228230 public void testDateReturnsNullWhenKeyDoesntExit (){
229231 assertNull (new JobParameters ().getDate ("keythatdoesntexist" ));
230232 }
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+ }
231244}
You can’t perform that action at this time.
0 commit comments