Skip to content

Commit 0b5a670

Browse files
committed
Fix prevent dirty flag from being set to false when pushing null
1 parent b4f4111 commit 0b5a670

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ public void put(String key, @Nullable Object value) {
133133
}
134134
else {
135135
Object result = this.map.remove(key);
136-
this.dirty = result != null;
136+
137+
if (!this.dirty) {
138+
this.dirty = result != null;
139+
}
137140
}
138141
}
139142

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,16 @@ void testNotDirtyWithDuplicate() {
8888
}
8989

9090
@Test
91-
void testNotDirtyWithRemoveMissing() {
91+
void testDirtyWithRemoveMissing() {
9292
context.putString("1", "test");
9393
assertTrue(context.isDirty());
94-
context.putString("1", null); // remove an item that was present
94+
95+
context.putString("1", null);
9596
assertTrue(context.isDirty());
96-
context.putString("1", null); // remove a non-existent item
97+
98+
context.clearDirtyFlag();
99+
100+
context.putString("1", null);
97101
assertFalse(context.isDirty());
98102
}
99103

0 commit comments

Comments
 (0)