Github user aledsage commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/462#discussion_r89771711
--- Diff:
core/src/main/java/org/apache/brooklyn/core/config/BasicConfigInheritance.java
---
@@ -170,12 +306,88 @@ public String getConflictResolutionStrategy() {
return conflictResolutionStrategy;
}
+ @Deprecated /** @deprecated since 0.10.0 when it was introduced,
prefer {@link #getLocalDefaultResolvesWithAncestorValue()} */
public boolean getUseLocalDefaultValue() {
- return useLocalDefaultValue;
+ return getLocalDefaultResolvesWithAncestorValue();
+ }
+
+ /** see {@link #localDefaultResolvesWithAncestorValue} */
+ public boolean getLocalDefaultResolvesWithAncestorValue() {
+ if (localDefaultResolvesWithAncestorValue==null) {
+ // in case some legacy path is using an improperly
deserialized object
+ log.warn("Encountered legacy "+this+" with null
localDefaultResolvesWithAncestorValue; transforming", new Throwable("stack
trace for legacy "+this));
+ readResolve();
+ }
+ return localDefaultResolvesWithAncestorValue;
+ }
+
+ public boolean getAncestorDefaultInheritable() {
+ if (ancestorDefaultInheritable==null) {
+ log.warn("Encountered legacy "+this+" with null
ancestorDefaultInheritable; transforming", new Throwable("stack trace for
legacy "+this));
+ readResolve();
+ }
+ return ancestorDefaultInheritable;
}
+ // standard deserialization method
+ private ConfigInheritance readResolve() {
+ try {
+ if (useLocalDefaultValue!=null) {
+ // move away from useLocalDefaultValue to
localDefaultResolvesWithAncestorValue
+
+ Field fNew =
getClass().getDeclaredField("localDefaultResolvesWithAncestorValue");
+ fNew.setAccessible(true);
+ Field fOld =
getClass().getDeclaredField("useLocalDefaultValue");
+ fOld.setAccessible(true);
+
+ if (fNew.get(this)==null) {
+ fNew.set(this, useLocalDefaultValue);
+ } else {
+ if (!fNew.get(this).equals(useLocalDefaultValue)) {
+ throw new IllegalStateException("Incompatible
values detected for "+fOld+" ("+fOld.get(this)+") and "+fNew+"
("+fNew.get(this)+")");
+ }
+ }
+ fOld.set(this, null);
+ }
+
+ if (ancestorDefaultInheritable==null) {
+ Field f =
getClass().getDeclaredField("ancestorDefaultInheritable");
+ f.setAccessible(true);
+ f.set(this, true);
+ }
+
+ } catch (Exception e) {
+ throw Exceptions.propagate(e);
+ }
+
+ for (ConfigInheritance knownMode: Arrays.asList(
+ NOT_REINHERITED, NOT_REINHERITED_ELSE_DEEP_MERGE,
NEVER_INHERITED, OVERWRITE, DEEP_MERGE)) {
+ if (equals(knownMode)) return knownMode;
--- End diff --
I don't understand how this works. I added a simple test to
`XmlMementoSerializerTest`, which fails:
```
@Test
public void testConfigInheritanceVals() throws Exception {
ConfigInheritance val = BasicConfigInheritance.NEVER_INHERITED;
ConfigInheritance newVal = assertSerializeAndDeserialize(val); //
TODO this line fails
assertSame(val, newVal);
}
```
It fails because the deserialized object has `null` for its `delegate`
field. It feels to me like the `equals(knownMode)` will always return false
because the deserialized object's `delegate` field will never have been set.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---