Skip to content

ExecutionContext dirty flag is never cleared #5249

@marschall

Description

@marschall

Bug description
The dirty flag of ExecutionContext is never cleared because org.springframework.batch.infrastructure.item.ExecutionContext#clearDirtyFlag() is never called.

Environment
Spring Batch version 6.0.2
Java version: 17.0.1
Database: H2 2.4.240

Steps to reproduce

  • Dirty a job or step execution context by calling one of the put* methods
  • Call JobRepository#updateExecutionContext
  • Call ExecutionContext#isDirty()

Expected behavior
I would expect org.springframework.batch.core.repository.JobRepository#updateExecutionContext(StepExecution) and org.springframework.batch.core.repository.JobRepository#updateExecutionContext(JobExecution) to clear the dirty flag.

Minimal Complete Reproducible example
Add to org.springframework.batch.core.repository.support.AbstractJobRepositoryIntegrationTests

	/*
	 * Save execution context clears the dirty flag.
	 */
	@Test
	void testUpdateRestesDirtyFlag() {
		JobInstance jobInstance = jobRepository.createJobInstance(job.getName(), jobParameters);
		JobExecution jobExec = jobRepository.createJobExecution(jobInstance, jobParameters, new ExecutionContext());
		jobExec.setStartTime(LocalDateTime.now());
		ExecutionContext ctx = new ExecutionContext();
		ctx.put("crashedPosition", 7);
		jobExec.setExecutionContext(ctx);
		assertTrue(ctx.isDirty());
		jobRepository.updateExecutionContext(jobExec);
		assertFalse(ctx.isDirty());
		
		Step step = new StepSupport("step1");
		StepExecution stepExec = jobRepository.createStepExecution(step.getName(), jobExec);
		ctx = new ExecutionContext(ctx);
		ctx.put("crashedPosition", 8);
		stepExec.setExecutionContext(ctx);
		assertTrue(ctx.isDirty());
		jobRepository.updateExecutionContext(stepExec);
		assertFalse(ctx.isDirty());
	}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions