diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java b/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java index 8704ebc35..b34d6e9c8 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMappingInterface.java @@ -47,7 +47,7 @@ protected ConfigMappingInterface computeValue(final Class type) { ConfigMappingInterface(final Class interfaceType, final ConfigMappingInterface[] superTypes, final Property[] properties) { this.interfaceType = interfaceType; - this.className = interfaceType.getName() + interfaceType.getName().hashCode() + "Impl"; + this.className = getImplementationClassName(interfaceType); this.superTypes = superTypes; List filteredProperties = new ArrayList<>(); @@ -67,6 +67,15 @@ protected ConfigMappingInterface computeValue(final Class type) { this.toStringMethod = toStringMethod; } + static String getImplementationClassName(Class type) { + // do not use string concatenation here + // make sure the impl name doesn't clash with potential user classes + String className = type.getName(); + StringBuilder implementationClassName = new StringBuilder(className.length() + 8); + implementationClassName.append(className).append("$$CMImpl"); + return implementationClassName.toString(); + } + /** * Get the configuration interface information for the given interface class. This information is cached. * diff --git a/implementation/src/main/java/io/smallrye/config/ConfigMappingLoader.java b/implementation/src/main/java/io/smallrye/config/ConfigMappingLoader.java index bb9c85023..bbbde4079 100644 --- a/implementation/src/main/java/io/smallrye/config/ConfigMappingLoader.java +++ b/implementation/src/main/java/io/smallrye/config/ConfigMappingLoader.java @@ -127,7 +127,8 @@ static T configMappingObject(final Class interfaceType, final ConfigMappi @SuppressWarnings("unchecked") public static Class getImplementationClass(final Class type) { try { - Class implementationClass = type.getClassLoader().loadClass(type.getName() + type.getName().hashCode() + "Impl"); + Class implementationClass = type.getClassLoader() + .loadClass(ConfigMappingInterface.getImplementationClassName(type)); if (type.isAssignableFrom(implementationClass)) { return (Class) implementationClass; }