Skip to content

Commit

Permalink
Fix exception when parsing empty values in DefaultJobParametersConverter
Browse files Browse the repository at this point in the history
Resolves #4505
  • Loading branch information
fmbenhassine committed Feb 14, 2024
1 parent 2fbdcd4 commit 0093e44
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -168,7 +168,11 @@ protected JobParameter<?> decode(String encodedJobParameter) {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,6 +20,7 @@

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;
Expand Down Expand Up @@ -129,6 +130,22 @@ void testGetParametersWithBogusLong() {
}
}

@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() {

Expand Down

0 comments on commit 0093e44

Please sign in to comment.