Skip to content

Switching incrementers causes jobs to have old job parameters #4073

Closed
@lifeweaver

Description

@lifeweaver

Bug description
Switching the incrementer for a job causes new instances of that job to keep the old incrementer's parameters around, causing errors if you have a job parameters validator.

Actual error: "JobParametersInvalidException: The JobParameters contains keys that are not explicitly optional or required: [run.id]"

Environment
Spring boot 2.6.4
Spring batch 4.3.5
Java 1.8.0_312
H2 database saved to file

Steps to reproduce
If you start with the code from https://github.com/Apress/def-guide-spring-batch/blob/7db62ca34a1c582fce722f4f266681f29d29b12d/Chapter04/src/main/java/com/example/Chapter04/jobs/HelloWorldJob.java, you should be almost there

  1. New project from spring boot initializer with spring batch, and h2
  2. Create simple job with a DefaultJobParametersValidator with 'run.id', and the RunIdIncrementer
  3. Run the job via the command line
  4. Switch the incrementer to something else that doesn't use 'run.id' and remove 'run.id' from your validator, adding your new parameter name
  5. Run your job again, and note the error about 'run.id' being "not explicitly optional or required".

Expected behavior
For the new job to work, without caring that the old job use a different incrementor

I believe the JobParametersBuilder.getNextJobParameters() is at fault, specifically:
nextParameters = incrementer.getNext(previousExecution.getJobParameters());
It appears to use the previous execution's job parameters, which would have the old, now invalid, parameter.

This is for sure an edge case, how often, would someone change the incrementer for a job? And I'm sure I can work around this issue if I changed my job name or deleted my h2 database. Hopefully there wasn't some warning about changing the incremeter that I missed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions