Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultJobParametersConverter throws java.lang.ArrayIndexOutOfBoundsException if input is empty string #4505

Closed
klrs opened this issue Dec 1, 2023 · 2 comments
Labels
for: backport-to-5.0.x Issues that will be back-ported to the 5.0.x line for: backport-to-5.1.x Issues that will be back-ported to the 5.1.x line in: core type: bug
Milestone

Comments

@klrs
Copy link

klrs commented Dec 1, 2023

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"));

    }
}
@klrs klrs added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Dec 1, 2023
@hwan33
Copy link
Contributor

hwan33 commented Dec 11, 2023

It seems that it is impossible to distinguish whether its value is null or empty string.
StringUtils.commaDelimitedListToStringArray(encodedJobParameter) returns EMPTY_STRING_ARRAY for both values.

@fmbenhassine
Copy link
Contributor

Thank you for raising this issue! The framework should not fail with an java.lang.ArrayIndexOutOfBoundsException if the value is empty. Job parameters are not designed to accept null values, so in that case the value should be an empty String.

@fmbenhassine fmbenhassine added in: core and removed status: waiting-for-triage Issues that we did not analyse yet labels Feb 14, 2024
@fmbenhassine fmbenhassine added this to the 5.2.0 milestone Feb 14, 2024
@fmbenhassine fmbenhassine added for: backport-to-5.0.x Issues that will be back-ported to the 5.0.x line for: backport-to-5.1.x Issues that will be back-ported to the 5.1.x line labels Feb 14, 2024
This was referenced Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: backport-to-5.0.x Issues that will be back-ported to the 5.0.x line for: backport-to-5.1.x Issues that will be back-ported to the 5.1.x line in: core type: bug
Projects
None yet
Development

No branches or pull requests

3 participants