ZEST-107 Fix JSONEntityState clone logic
The cloneStateIfGlobalStateLoaded() method of JSONEntityState is called
before any change is made to the entity state.
This method starts with the following check:
if( isStateNotCloned() )
{
return;
}
// Do the clone
And the (private) isStateNotCloned() method returns:
status == EntityStatus.LOADED
IOW, the code says that it will clone state if status is loaded,
but does the opposite!
Rewriting the cloneStateIfGlobalStateLoaded() method,
as Tibor suggested, fixes the issue:
if( status != EntityState.LOADED )
{
return;
}
// Do the clone
I removed the isStateNotCloned() method BTW as it was not used elsewhere
and the code is simpler without it.
diff --git a/core/spi/src/main/java/org/qi4j/spi/entitystore/helpers/JSONEntityState.java b/core/spi/src/main/java/org/qi4j/spi/entitystore/helpers/JSONEntityState.java
index 435acde..ae60809 100644
--- a/core/spi/src/main/java/org/qi4j/spi/entitystore/helpers/JSONEntityState.java
+++ b/core/spi/src/main/java/org/qi4j/spi/entitystore/helpers/JSONEntityState.java
@@ -308,14 +308,9 @@
}
}
- boolean isStateNotCloned()
- {
- return status == EntityStatus.LOADED;
- }
-
void cloneStateIfGlobalStateLoaded()
{
- if( isStateNotCloned() )
+ if( status != EntityStatus.LOADED )
{
return;
}