Repository: spring-projects/spring-batch

Issue #4505: DefaultJobParametersConverter throws java.lang.ArrayIndexOutOfBoundsException if input is empty string
Created: 2023-12-01T14:01:46Z
Bug description
DefaultJobParamatersConverter class's private parseValue(String encodedJobParameter) method throws java.lang.ArrayIndexOutOfBoundsException if the parameter encodedJobParameter is null or empty.
This causes the batch app started from the command line to not accept empty command line arguments in the format arg1=.
Environment
Java 17
Spring Boot 3.1.4
Spring Batch 5.0.3
Expected behavior
Job parameter should be null or empty.
Minimal Complete Reproducible example
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Properties;

import org.junit.jupiter.api.Test;
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class Test {

    @Autowired
    DefaultJobParametersConverter converter;

    @Test
    void testConversion() {
        Properties props = new Properties();
        props.put("arg1", "");
        assertEquals("", converter.getJobParameters(props).getString("arg1"));

    }
}

Duplicate issue #4622: When an parameter with empty value is provided, `DefaultJobParametersConverter` fails with not user-friendly message.
Created: 2024-06-19T05:24:20Z
Please do a quick search on Github issues first, there might be already a duplicate issue for the one you are about to create.
If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:
Bug description
If the job parameter given like
param1= ,param2=foo

org.springframework.batch.core.converter.DefaultJobParametersConverter#parseValue fails with ArrayIndexOutOfBoundsException.
Environment
Spring Batch 5.1.0
Steps to reproduce
pass args to the runner like
param1= ,param2=foo

Expected behavior
If the intention is not to allow empty values, the error message should be more user-friendly.
If not, the system should create and bind a JobParameter even for empty values.
Minimal Complete Reproducible example
replacing with attachment of stacktrace
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at org.springframework.batch.core.converter.DefaultJobParametersConverter.parseValue(DefaultJobParametersConverter.java:172)
	at org.springframework.batch.core.converter.DefaultJobParametersConverter.decode(DefaultJobParametersConverter.java:158)
	at org.springframework.batch.core.converter.DefaultJobParametersConverter.getJobParameters(DefaultJobParametersConverter.java:104)
	at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:173)
	at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:169)
	at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:164)

Closing comment (2024-10-27T05:29:48Z): This issue seems to be the same as #4505 and appears to have been resolved with commit d8d76ab, so it should be okay to close this.