From 2c98c7d3649a99ffc80d00d7ba37beea6ff1537f Mon Sep 17 00:00:00 2001 From: HeoSeokMun Date: Mon, 28 Oct 2024 20:38:32 +0900 Subject: [PATCH] Fix prevent dirty flag from being set to false when pushing null --- .../org/springframework/batch/item/ExecutionContext.java | 5 ++++- .../springframework/batch/item/ExecutionContextTests.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java index be26dbc9cb..19317425b7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionContext.java @@ -133,7 +133,10 @@ public void put(String key, @Nullable Object value) { } else { Object result = this.map.remove(key); - this.dirty = result != null; + + if (!this.dirty) { + this.dirty = result != null; + } } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java index 5ec7b794a4..7e9052624e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java @@ -88,11 +88,13 @@ void testNotDirtyWithDuplicate() { } @Test - void testNotDirtyWithRemoveMissing() { + void testDirtyWithRemoveMissing() { context.putString("1", "test"); assertTrue(context.isDirty()); context.putString("1", null); // remove an item that was present assertTrue(context.isDirty()); + + context.clearDirtyFlag(); context.putString("1", null); // remove a non-existent item assertFalse(context.isDirty()); }