spring-projects / spring-batch

Spring Batch is a framework for writing batch applications using Java and Spring
http://projects.spring.io/spring-batch/
Apache License 2.0
2.73k stars 2.35k forks source link

ExecutionContext dirty flag is reset by a new put #4685

Open mjwiq opened 1 month ago

mjwiq commented 1 month ago

Bug description ExecutionContext.isDirty is supposed to tell if the context has been changed with a "put" operation since the dirty flag was last cleared (or the context was created). Only the clearDirtyFlag method is supposed to clear the flag once it has been set.

Instead, a "put" that sets a value to the same as its original value will also set the dirty flag to false, even if another put has happened before that did make a meaningfull change

Environment Any code since commit https://github.com/spring-projects/spring-batch/commit/963142cfa837e5d766013510ea4063bce8167dd2 will have this issue. The environment is not relevant

Steps to reproduce

Expected behavior The dirty flag will still be true

Minimal Complete Reproducible example

@Test
void dirtyContextIsDirty() {
    ExecutionContext context = new ExecutionContext();
    context.put("hello", "world");
    assert context.isDirty(); // succeeds
    context.put("hello", "world");
    assert context.isDirty(); // fails
}

Further context I did not have a problem with this yet. I just stumbled across it when looking at ExecutionContext The issue was mentioned, but not addressed in https://github.com/spring-projects/spring-batch/issues/2020#issuecomment-566289477

Proposed fix

this.dirty = this.dirty || result == null || !result.equals(value);
GGHDMS commented 3 weeks ago

i create fix pr #4691