Skip to content

Commit

Permalink
Validate mapping annotation only in SmallRyeConfigBuilder (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Nov 12, 2024
1 parent 9e13393 commit 84121f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public static ConfigMappingInterface getConfigMapping(final Class<?> type) {
}

static Class<?> getConfigMappingClass(final Class<?> type) {
validateAnnotations(type);

ConfigMappingClass configMappingClass = ConfigMappingClass.getConfigurationClass(type);
if (configMappingClass == null) {
return type;
Expand Down Expand Up @@ -170,16 +168,6 @@ static Class<?> loadClass(final Class<?> parent, final ConfigMappingMetadata con
}
}

static void validateAnnotations(Class<?> type) {
if (!type.isInterface() && type.isAnnotationPresent(ConfigMapping.class)) {
throw ConfigMessages.msg.mappingAnnotationNotSupportedInClass(type);
}

if (type.isInterface() && type.isAnnotationPresent(ConfigProperties.class)) {
throw ConfigMessages.msg.propertiesAnnotationNotSupportedInInterface(type);
}
}

/**
* Do not remove this method or inline it. It is keep separate on purpose, so it is easier to substitute it with
* the GraalVM API for native image compilation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import jakarta.annotation.Priority;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperties;
import org.eclipse.microprofile.config.spi.ConfigBuilder;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
Expand Down Expand Up @@ -541,10 +542,6 @@ public SmallRyeConfigBuilder withMapping(ConfigClass configClass) {
return this;
}

/**
* @deprecated Use {@link SmallRyeConfigBuilder#withMapping(ConfigClass)} instead.
*/
@Deprecated(forRemoval = true)
public SmallRyeConfigBuilder withMapping(Class<?> klass, String prefix) {
mappingsBuilder.mapping(klass, prefix);
return this;
Expand Down Expand Up @@ -777,6 +774,7 @@ public final class MappingBuilder {
private final StringBuilder sb = new StringBuilder();

public void mapping(ConfigClass configClass) {
validateAnnotations(configClass.getKlass());
mapping(configClass.getKlass(), configClass.getPrefix());
}

Expand Down Expand Up @@ -823,6 +821,16 @@ public Map<Class<?>, Set<String>> getMappings() {
public List<String> getIgnoredPaths() {
return ignoredPaths;
}

private void validateAnnotations(Class<?> type) {
if (!type.isInterface() && type.isAnnotationPresent(ConfigMapping.class)) {
throw ConfigMessages.msg.mappingAnnotationNotSupportedInClass(type);
}

if (type.isInterface() && type.isAnnotationPresent(ConfigProperties.class)) {
throw ConfigMessages.msg.propertiesAnnotationNotSupportedInInterface(type);
}
}
}

static class ConverterWithPriority {
Expand Down

0 comments on commit 84121f3

Please sign in to comment.