diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/GemFireProperties.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/GemFireProperties.java index 5977576c..e2a32f3c 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/GemFireProperties.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/GemFireProperties.java @@ -182,14 +182,16 @@ public enum GemFireProperties { String safePropertyName = String.valueOf(propertyName).trim(); - boolean gemfireDotPrefixed = safePropertyName.startsWith(PROPERTY_NAME_PREFIX); + boolean gemfireDotPrefixed = safePropertyName.startsWith(GEMFIRE_PROPERTY_NAME_PREFIX); int index = safePropertyName.lastIndexOf("."); - return gemfireDotPrefixed && index > -1 ? safePropertyName.substring(index + 1) : propertyName; + return gemfireDotPrefixed && index > -1 + ? safePropertyName.substring(index + 1) + : propertyName; } - private @Nullable Class nullSafeType(@Nullable Object target, @Nullable Class defaultType) { + private static @Nullable Class nullSafeType(@Nullable Object target, @Nullable Class defaultType) { return target != null ? target.getClass() : defaultType; } @@ -197,7 +199,7 @@ public enum GemFireProperties { private static final Object DEFAULT_PROPERTY_VALUE = null; - public static final String PROPERTY_NAME_PREFIX = "gemfire."; + public static final String GEMFIRE_PROPERTY_NAME_PREFIX = "gemfire."; private final Class propertyType; @@ -254,8 +256,12 @@ public enum GemFireProperties { * @see #getDefaultValueAsType(Class) * @see #getType() */ + @SuppressWarnings("unchecked") public @NonNull T getDefaultValueAsType() { - return getDefaultValueAsType(getType()); + + Class propertyType = (Class) getType(); + + return getDefaultValueAsType(propertyType); } /** @@ -269,15 +275,20 @@ public enum GemFireProperties { * @see #getDefaultValue() * @see #getType() */ - @SuppressWarnings("unchecked") - public T getDefaultValueAsType(Class type) { + public @NonNull T getDefaultValueAsType(@NonNull Class type) { + + Assert.notNull(type, "Target type must not be null"); Object defaultValue = getDefaultValue(); - Class defaultValueType = nullSafeType(defaultValue, getType()); + Class propertyType = getType(); + Class defaultValueType = nullSafeType(defaultValue, propertyType); - if (this.conversionService.canConvert(defaultValueType, type)) { - return (T) this.conversionService.convert(defaultValue, type); + if (type.isInstance(defaultValue)) { + return type.cast(defaultValue); + } + else if (this.conversionService.canConvert(defaultValueType, type)) { + return this.conversionService.convert(defaultValue, type); } throw newIllegalArgumentException("Cannot convert value [%s] from type [%s] to type [%s]", @@ -285,9 +296,9 @@ public enum GemFireProperties { } /** - * Gets the {@link String name} of this property. + * Gets the {@link String name} of {@literal this} property. * - * @return the {@link String name} of this property. + * @return the {@link String name} of {@literal this} property. * @see java.lang.String */ public @NonNull String getName() { @@ -295,9 +306,9 @@ public enum GemFireProperties { } /** - * Gets the declared {@link Class type} of this property. + * Gets the declared {@link Class type} of {@literal this} property. * - * @return the declared {@link Class type} of this property. + * @return the declared {@link Class type} of {@literal this} property. * @see java.lang.Class */ public @NonNull Class getType() { @@ -308,7 +319,7 @@ public enum GemFireProperties { * @inheritDoc */ @Override - public String toString() { + public @NonNull String toString() { return getName(); } } diff --git a/spring-data-geode/src/main/java/org/springframework/data/gemfire/util/DistributedSystemUtils.java b/spring-data-geode/src/main/java/org/springframework/data/gemfire/util/DistributedSystemUtils.java index 65f2d73b..6ce9b7a4 100644 --- a/spring-data-geode/src/main/java/org/springframework/data/gemfire/util/DistributedSystemUtils.java +++ b/spring-data-geode/src/main/java/org/springframework/data/gemfire/util/DistributedSystemUtils.java @@ -47,7 +47,7 @@ public abstract class DistributedSystemUtils extends SpringUtils { public static final String DURABLE_CLIENT_ID_PROPERTY_NAME = GemFireProperties.DURABLE_CLIENT_ID.getName(); public static final String DURABLE_CLIENT_TIMEOUT_PROPERTY_NAME = GemFireProperties.DURABLE_CLIENT_TIMEOUT.getName(); - public static final String GEMFIRE_PREFIX = GemFireProperties.PROPERTY_NAME_PREFIX; + public static final String GEMFIRE_PREFIX = GemFireProperties.GEMFIRE_PROPERTY_NAME_PREFIX; public static final String NAME_PROPERTY_NAME = GemFireProperties.NAME.getName(); public static Properties configureDurableClient(Properties gemfireProperties, diff --git a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java index 61c02a1b..41f3dd46 100644 --- a/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java +++ b/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/PeerCacheApplicationWithAddedCacheServerIntegrationTests.java @@ -67,7 +67,7 @@ public class PeerCacheApplicationWithAddedCacheServerIntegrationTests gemfireLocator = run(TestLocatorConfiguration.class, "-Dspring.data.gemfire.locator.port=" + locatorPort, - String.format("-D%1$s%2$s=%3$s", GemFireProperties.PROPERTY_NAME_PREFIX, + String.format("-D%1$s%2$s=%3$s", GemFireProperties.GEMFIRE_PROPERTY_NAME_PREFIX, GemFireProperties.ENABLE_CLUSTER_CONFIGURATION.getName(), false)); waitForServerToStart("localhost", locatorPort);