diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java index d531257b0f..c5c735f7b4 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/main/java/org/apache/nifi/dbcp/DBCPConnectionPool.java @@ -272,7 +272,12 @@ public class DBCPConnectionPool extends AbstractDBCPConnectionPool implements DB .map(descriptor -> { final PropertyValue propertyValue = context.getProperty(descriptor); if (descriptor.isSensitive()) { - final String propertyName = StringUtils.substringAfter(descriptor.getName(), SENSITIVE_PROPERTY_PREFIX); + final String propertyName; + if (StringUtils.startsWith(descriptor.getName(), SENSITIVE_PROPERTY_PREFIX)) { + propertyName = StringUtils.substringAfter(descriptor.getName(), SENSITIVE_PROPERTY_PREFIX); + } else { + propertyName = descriptor.getName(); + } return new AbstractMap.SimpleEntry<>(propertyName, propertyValue.getValue()); } else { return new AbstractMap.SimpleEntry<>(descriptor.getName(), propertyValue.evaluateAttributeExpressions().getValue()); diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java index bb6b08e992..747791324b 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java @@ -32,6 +32,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.opentest4j.AssertionFailedError; import java.io.File; import java.io.IOException; @@ -162,6 +163,15 @@ public class DBCPServiceTest { assertConnectionNotNullDynamicProperty("SENSITIVE.create", "true"); } + @Test + public void testGetConnectionSensitiveDynamicPropertyWithoutPrefixAndWithPrefixShouldThrowException() { + runner.setProperty(service, "SENSITIVE.create", "true"); + runner.setProperty(service, "create", "true"); + + final AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> runner.enableControllerService(service)); + assertTrue(e.getMessage().contains("Duplicate")); + } + @Test public void testGetConnectionExecuteStatements() throws SQLException { runner.enableControllerService(service);