Skip to content

Commit

Permalink
Fix dirty flag on ExecutionContext
Browse files Browse the repository at this point in the history
Before this commit, the dirty flag was reset
on any put operation, even those that replace
existing keys with the same values.

This commit fixes the dirty flag to be cleared
only by meaningful put operations.

Resolves #4685
Resolves #4692
  • Loading branch information
GGHDMS authored and fmbenhassine committed Feb 26, 2025
1 parent a79b6f7 commit 42b1464
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2023 the original author or authors.
* Copyright 2006-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,7 @@
* @author Lucas Ward
* @author Douglas Kaminsky
* @author Mahmoud Ben Hassine
* @author Seokmun Heo
*/
public class ExecutionContext implements Serializable {

Expand Down Expand Up @@ -124,19 +125,21 @@ public void putDouble(String key, double value) {
public void put(String key, @Nullable Object value) {
if (value != null) {
Object result = this.map.put(key, value);
this.dirty = result == null || !result.equals(value);
this.dirty = this.dirty || result == null || !result.equals(value);
}
else {
Object result = this.map.remove(key);
this.dirty = result != null;
this.dirty = this.dirty || result != null;
}
}

/**
* Indicates if context has been changed with a "put" operation since the dirty flag
* was last cleared. Note that the last time the flag was cleared might correspond to
* creation of the context.
* @return True if "put" operation has occurred since flag was last cleared
* creation of the context. A context is only dirty if a new value is put or an old
* one is removed.
* @return True if a new value was put or an old one was removed since the last time
* the flag was cleared
*/
public boolean isDirty() {
return this.dirty;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2024 the original author or authors.
* Copyright 2006-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@
/**
* @author Lucas Ward
* @author Mahmoud Ben Hassine
*
* @author Seokmun Heo
*/
class ExecutionContextTests {

Expand Down Expand Up @@ -94,11 +94,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());
}
Expand Down Expand Up @@ -167,6 +169,15 @@ void testCopyConstructorNullInput() {
assertTrue(context.isEmpty());
}

@Test
void testDirtyWithDuplicate() {
ExecutionContext context = new ExecutionContext();
context.put("1", "testString1");
assertTrue(context.isDirty());
context.put("1", "testString1"); // put the same value
assertTrue(context.isDirty());
}

/**
* Value object for testing serialization
*/
Expand Down

0 comments on commit 42b1464

Please sign in to comment.