diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractComponentNode.java b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractComponentNode.java index 89bf5156d1..0a2f5f2e8a 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractComponentNode.java +++ b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/controller/AbstractComponentNode.java @@ -555,10 +555,11 @@ public abstract class AbstractComponentNode implements ComponentNode { // Keep setProperty/removeProperty private so that all calls go through setProperties private void setProperty(final PropertyDescriptor descriptor, final PropertyConfiguration propertyConfiguration, final Function valueToCompareFunction) { + final PropertyConfiguration propertyModComparisonValue = valueToCompareFunction.apply(descriptor); + // Remove current PropertyDescriptor to force updated instance references final PropertyConfiguration removed = properties.remove(descriptor); - final PropertyConfiguration propertyModComparisonValue = valueToCompareFunction.apply(descriptor); properties.put(descriptor, propertyConfiguration); final String effectiveValue = propertyConfiguration.getEffectiveValue(getParameterContext()); final String resolvedValue = resolveAllowableValue(effectiveValue, descriptor); diff --git a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestAbstractComponentNode.java b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestAbstractComponentNode.java index 1d2116debe..40d72fb8aa 100644 --- a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestAbstractComponentNode.java +++ b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestAbstractComponentNode.java @@ -306,6 +306,37 @@ public class TestAbstractComponentNode { assertFalse(updatedPropertyDescriptor.isSensitive()); } + @Test + public void testSetPropertiesPropertyModified() { + final String propertyValueModified = PROPERTY_VALUE + "-modified"; + final List propertyModifications = new ArrayList<>(); + final AbstractComponentNode node = new LocalComponentNode() { + @Override + protected void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) { + propertyModifications.add(new PropertyModification(descriptor, oldValue, newValue)); + super.onPropertyModified(descriptor, oldValue, newValue); + } + }; + + final Map properties = new HashMap<>(); + properties.put(PROPERTY_NAME, PROPERTY_VALUE); + node.setProperties(properties); + + assertEquals(1, propertyModifications.size()); + PropertyModification mod = propertyModifications.get(0); + assertNull(mod.getPreviousValue()); + assertEquals(PROPERTY_VALUE, mod.getUpdatedValue()); + propertyModifications.clear(); + + properties.put(PROPERTY_NAME, propertyValueModified); + node.setProperties(properties); + + assertEquals(1, propertyModifications.size()); + mod = propertyModifications.get(0); + assertEquals(PROPERTY_VALUE, mod.getPreviousValue()); + assertEquals(propertyValueModified, mod.getUpdatedValue()); + } + @Test public void testSetPropertiesSensitiveDynamicPropertyNames() { final AbstractComponentNode node = new LocalComponentNode();