Skip to content

CommandLineJobOperator.parse() truncates parameter values containing '=' #5295

@Wordbe

Description

@Wordbe

Bug description

CommandLineJobOperator.parse() uses String.split("=") without a limit, which splits on every = character. This causes two problems:

  1. Parameter values containing = get truncated (e.g. URLs with query strings)
  2. Parameters without = throw ArrayIndexOutOfBoundsException

The deprecated CommandLineJobRunner and Spring Boot's JobLauncherApplicationRunner both use StringUtils.splitArrayElementsIntoProperties which correctly splits only on the first =.

Environment

Spring Batch 6.0.x (all versions since CommandLineJobOperator was introduced in 6.0)

Steps to reproduce

Run a job via CommandLineJobOperator with a parameter containing = in the value:

java ... CommandLineJobOperator com.example.MyJobConfig start myJob url=http://example.com?id=123

Expected behavior

The parameter should be parsed as urlhttp://example.com?id=123.

Current behavior

split("=") produces ["url", "http://example.com?id", "123"], so only http://example.com?id is stored as the value. The rest is lost.

Relevant code

https://github.com/spring-projects/spring-batch/blob/main/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/CommandLineJobOperator.java#L406-L413

For comparison, JobLauncherApplicationRunner handles this correctly:
https://github.com/spring-projects/spring-boot/blob/main/module/spring-boot-batch/src/main/java/org/springframework/boot/batch/autoconfigure/JobLauncherApplicationRunner.java#L148

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions