diff --git a/docs/release-notes.html b/docs/release-notes.html index a9d90e93f..01cb82695 100644 --- a/docs/release-notes.html +++ b/docs/release-notes.html @@ -97,6 +97,15 @@

Version 7.0.1



+
  • + Added a StaticUtils.setSystemPropertyIfNotAlreadyDefined method that can be used + to set the value of a system property, but only if that property is not already + set. If the property already has a value, then the existing value will be + retained regardless of whether it is the same as or different from the provided + value. +

    +
  • +
  • Updated the OID registry to include records for a number of collation matching rules. diff --git a/src/com/unboundid/util/BouncyCastleFIPSHelper.java b/src/com/unboundid/util/BouncyCastleFIPSHelper.java index 9a0c7351c..3613add17 100644 --- a/src/com/unboundid/util/BouncyCastleFIPSHelper.java +++ b/src/com/unboundid/util/BouncyCastleFIPSHelper.java @@ -360,29 +360,12 @@ static void setPropertiesForPingIdentityServer() return; } - setPropertyIfNotDefined(PROPERTY_APPROVED_ONLY, "true"); - setPropertyIfNotDefined(PROPERTY_ALLOW_RSA_MULTI_USE, "true"); - setPropertyIfNotDefined(PROPERTY_ENABLE_MD5, "true"); - } - - - - /** - * Sets the specified system property with the given value, but only if it is - * not already set. - * - * @param name The name of the property to set. It must not be - * {@code null}. - * @param value The value to use for the property. It must not be - * {@code null}. - */ - static void setPropertyIfNotDefined(@NotNull final String name, - @NotNull final String value) - { - if (StaticUtils.getSystemProperty(name) == null) - { - StaticUtils.setSystemProperty(name, value); - } + StaticUtils.setSystemPropertyIfNotAlreadyDefined(PROPERTY_APPROVED_ONLY, + "true"); + StaticUtils.setSystemPropertyIfNotAlreadyDefined( + PROPERTY_ALLOW_RSA_MULTI_USE, "true"); + StaticUtils.setSystemPropertyIfNotAlreadyDefined(PROPERTY_ENABLE_MD5, + "true"); } diff --git a/src/com/unboundid/util/StaticUtils.java b/src/com/unboundid/util/StaticUtils.java index e0b4fb323..6b2452319 100644 --- a/src/com/unboundid/util/StaticUtils.java +++ b/src/com/unboundid/util/StaticUtils.java @@ -476,7 +476,7 @@ public static String getSystemProperty(@NotNull final String name, * may not be permitted by some security managers, in which case the attempt * will have no effect. * - * @param name The name of the System property to set. It must not be + * @param name The name of the system property to set. It must not be * {@code null}. * @param value The value to use for the system property. If it is * {@code null}, then the property will be cleared. @@ -513,6 +513,37 @@ public static String setSystemProperty(@NotNull final String name, + /** + * Attempts to set the value of the specified system property, but only if the + * specified property does not already have a value. If the specified + * property is already set, then it will remain set to its current value. + * + * @param name The name of the system property to set. It must not be + * {@code null}. + * @param value The value to use for the system property if it is not + * already set. It must not be {@code null}. + * + * @return The existing value for the system property, if it was previously + * defined, or {@code null} if it did not already have a value. + */ + @NotNull() + public static String setSystemPropertyIfNotAlreadyDefined( + @NotNull final String name, + @NotNull final String value) + { + final String existingValue = getSystemProperty(name); + if (existingValue == null) + { + return setSystemProperty(name, value); + } + else + { + return existingValue; + } + } + + + /** * Attempts to clear the value of the specified system property. Note that * this may not be permitted by some security managers, in which case the diff --git a/tests/unit/src/com/unboundid/ldap/sdk/ProhibitedMethodCallsTestCase.java b/tests/unit/src/com/unboundid/ldap/sdk/ProhibitedMethodCallsTestCase.java index fb789f36a..32b25e90b 100644 --- a/tests/unit/src/com/unboundid/ldap/sdk/ProhibitedMethodCallsTestCase.java +++ b/tests/unit/src/com/unboundid/ldap/sdk/ProhibitedMethodCallsTestCase.java @@ -207,7 +207,7 @@ public void testSystemClearProperty(final File f) throws Exception { final Map> allowedExceptions = StaticUtils.mapOf( - "StaticUtils.java", StaticUtils.setOf(496, 506, 533, 537)); + "StaticUtils.java", StaticUtils.setOf(496, 506, 564, 568)); final Map unwrappedLines = unwrapSourceLines(readFileLines(f)); @@ -252,7 +252,7 @@ public void testSystemGetEnv(final File f) throws Exception { final Map> allowedExceptions = StaticUtils.mapOf( - "StaticUtils.java", StaticUtils.setOf(560, 564, 589, 593)); + "StaticUtils.java", StaticUtils.setOf(591, 595, 620, 624)); final Map unwrappedLines = unwrapSourceLines(readFileLines(f)); @@ -299,7 +299,7 @@ public void testLoggerLogLevel(final File f) { final Map> allowedExceptions = StaticUtils.mapOf( "Debug.java", StaticUtils.setOf(99), - "StaticUtils.java", StaticUtils.setOf(647, 670)); + "StaticUtils.java", StaticUtils.setOf(678, 701)); final Map unwrappedLines = unwrapSourceLines(readFileLines(f)); diff --git a/tests/unit/src/com/unboundid/util/BouncyCastleFIPSHelperTestCase.java b/tests/unit/src/com/unboundid/util/BouncyCastleFIPSHelperTestCase.java index ddf85e0b4..89dc2916b 100644 --- a/tests/unit/src/com/unboundid/util/BouncyCastleFIPSHelperTestCase.java +++ b/tests/unit/src/com/unboundid/util/BouncyCastleFIPSHelperTestCase.java @@ -38,7 +38,6 @@ import java.security.NoSuchProviderException; -import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; @@ -109,34 +108,4 @@ public void testLogging() BouncyCastleFIPSHelper.disableLogging(); assertEquals(logger.getLevel(), Level.OFF); } - - - - /** - * Provides test coverage for the ability to set system properties if they are - * not already defined. - * - * @throws Exception If an unexpected problem occurs. - */ - @Test() - public void testSetPropertyIfNotDefined() - throws Exception - { - final String propertyName = UUID.randomUUID().toString(); - final String propertyValue1 = UUID.randomUUID().toString(); - assertNull(StaticUtils.getSystemProperty(propertyName)); - - BouncyCastleFIPSHelper.setPropertyIfNotDefined(propertyName, - propertyValue1); - assertNotNull(StaticUtils.getSystemProperty(propertyName)); - assertEquals(StaticUtils.getSystemProperty(propertyName), propertyValue1); - - final String propertyValue2 = UUID.randomUUID().toString(); - assertFalse(propertyValue1.equals(propertyValue2)); - - BouncyCastleFIPSHelper.setPropertyIfNotDefined(propertyName, - propertyValue2); - assertNotNull(StaticUtils.getSystemProperty(propertyName)); - assertEquals(StaticUtils.getSystemProperty(propertyName), propertyValue1); - } } diff --git a/tests/unit/src/com/unboundid/util/StaticUtilsTestCase.java b/tests/unit/src/com/unboundid/util/StaticUtilsTestCase.java index e1a1403bc..2ff5f26b4 100644 --- a/tests/unit/src/com/unboundid/util/StaticUtilsTestCase.java +++ b/tests/unit/src/com/unboundid/util/StaticUtilsTestCase.java @@ -3269,6 +3269,41 @@ public void testGetSystemProperties() + /** + * Provides test coverage for the ability to set system properties if they are + * not already defined. + * + * @throws Exception If an unexpected problem occurs. + */ + @Test() + public void testSetSystemPropertyIfNotAlreadyDefined() + throws Exception + { + final String propertyName = UUID.randomUUID().toString(); + final String propertyValue1 = UUID.randomUUID().toString(); + assertNull(StaticUtils.getSystemProperty(propertyName)); + + String returnValue = StaticUtils.setSystemPropertyIfNotAlreadyDefined( + propertyName, propertyValue1); + assertNull(returnValue); + + assertNotNull(StaticUtils.getSystemProperty(propertyName)); + assertEquals(StaticUtils.getSystemProperty(propertyName), propertyValue1); + + final String propertyValue2 = UUID.randomUUID().toString(); + assertFalse(propertyValue1.equals(propertyValue2)); + + returnValue = StaticUtils.setSystemPropertyIfNotAlreadyDefined(propertyName, + propertyValue2); + assertNotNull(returnValue); + assertEquals(returnValue, propertyValue1); + + assertNotNull(StaticUtils.getSystemProperty(propertyName)); + assertEquals(StaticUtils.getSystemProperty(propertyName), propertyValue1); + } + + + /** * Tests the behavior of methods for interacting with environment variables. *