Skip to content

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

Closed
@klrs

Description

@klrs

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

    }
}

Activity

hwan33

hwan33 commented on Dec 11, 2023

@hwan33
Contributor

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

fmbenhassine commented on Feb 14, 2024

@fmbenhassine
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.

added this to the 5.2.0 milestone on Feb 14, 2024
added 2 commits that reference this issue on Feb 14, 2024
964df6d
0093e44
added a commit that references this issue on Feb 14, 2024
d8d76ab

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @fmbenhassine@klrs@hwan33

        Issue actions

          DefaultJobParametersConverter throws java.lang.ArrayIndexOutOfBoundsException if input is empty string · Issue #4505 · spring-projects/spring-batch