Skip to content

Commit

Permalink
Fix dirty flag set to false on same value put
Browse files Browse the repository at this point in the history
  • Loading branch information
GGHDMS committed Oct 27, 2024
1 parent cf44ca8 commit b4f4111
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 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-2024 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,7 +125,11 @@ 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);
boolean newDirty = result == null || !result.equals(value);

if (!this.dirty) {
this.dirty = newDirty;
}
}
else {
Object result = this.map.remove(key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2023 the original author or authors.
* Copyright 2006-2024 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 @@ -30,7 +30,7 @@
/**
* @author Lucas Ward
* @author Mahmoud Ben Hassine
*
* @author Seokmun Heo
*/
class ExecutionContextTests {

Expand Down Expand Up @@ -161,6 +161,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 b4f4111

Please sign in to comment.