Fix exception when parsing empty values in DefaultJobParametersConverter
Resolves #4505
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
* Copyright 2006-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -169,7 +169,11 @@ public class DefaultJobParametersConverter implements JobParametersConverter {
|
||||
}
|
||||
|
||||
private String parseValue(String encodedJobParameter) {
|
||||
return StringUtils.commaDelimitedListToStringArray(encodedJobParameter)[0];
|
||||
String[] tokens = StringUtils.commaDelimitedListToStringArray(encodedJobParameter);
|
||||
if (tokens.length == 0) {
|
||||
return "";
|
||||
}
|
||||
return tokens[0];
|
||||
}
|
||||
|
||||
private Class<?> parseType(String encodedJobParameter) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
* Copyright 2006-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.core.JobParameter;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -129,6 +130,22 @@ class DefaultJobParametersConverterTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetParametersWithEmptyValue() {
|
||||
// given
|
||||
String[] args = new String[] { "parameter=" };
|
||||
|
||||
// when
|
||||
JobParameters jobParameters = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
|
||||
|
||||
// then
|
||||
assertEquals(1, jobParameters.getParameters().size());
|
||||
JobParameter<?> parameter = jobParameters.getParameters().get("parameter");
|
||||
assertEquals("", parameter.getValue());
|
||||
assertEquals(String.class, parameter.getType());
|
||||
assertTrue(parameter.isIdentifying());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetParametersWithDoubleValueDeclaredAsLong() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user