Skip to content

Commit b4f4111

Browse files
committed
Fix dirty flag set to false on same value put
1 parent cf44ca8 commit b4f4111

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2023 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@
3737
* @author Lucas Ward
3838
* @author Douglas Kaminsky
3939
* @author Mahmoud Ben Hassine
40+
* @author Seokmun Heo
4041
*/
4142
public class ExecutionContext implements Serializable {
4243

@@ -124,7 +125,11 @@ public void putDouble(String key, double value) {
124125
public void put(String key, @Nullable Object value) {
125126
if (value != null) {
126127
Object result = this.map.put(key, value);
127-
this.dirty = result == null || !result.equals(value);
128+
boolean newDirty = result == null || !result.equals(value);
129+
130+
if (!this.dirty) {
131+
this.dirty = newDirty;
132+
}
128133
}
129134
else {
130135
Object result = this.map.remove(key);

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

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2023 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@
3030
/**
3131
* @author Lucas Ward
3232
* @author Mahmoud Ben Hassine
33-
*
33+
* @author Seokmun Heo
3434
*/
3535
class ExecutionContextTests {
3636

@@ -161,6 +161,15 @@ void testCopyConstructorNullInput() {
161161
assertTrue(context.isEmpty());
162162
}
163163

164+
@Test
165+
void testDirtyWithDuplicate() {
166+
ExecutionContext context = new ExecutionContext();
167+
context.put("1", "testString1");
168+
assertTrue(context.isDirty());
169+
context.put("1", "testString1"); // put the same value
170+
assertTrue(context.isDirty());
171+
}
172+
164173
/**
165174
* Value object for testing serialization
166175
*/

0 commit comments

Comments
 (0)