ProfilesValidator Class — spring-boot Architecture
Architecture documentation for the ProfilesValidator class in ProfilesValidator.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/context/config/ProfilesValidator.java lines 41–96
final class ProfilesValidator implements BindHandler {
private static final String ALLOWED_CHARS = "-_.+@";
private final boolean validate;
private ProfilesValidator(boolean validate) {
this.validate = validate;
}
@Override
public Object onSuccess(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) {
validate(result);
return result;
}
void validate(Object value, Supplier<String> wrappedExceptionMessage) {
try {
validate(value);
}
catch (IllegalStateException ex) {
throw new IllegalStateException(wrappedExceptionMessage.get(), ex);
}
}
private void validate(@Nullable Object value) {
if (!this.validate) {
return;
}
if (value instanceof Collection<?> list) {
list.forEach(this::validate);
return;
}
if (value instanceof Map<?, ?> map) {
map.forEach((k, v) -> validate(v));
return;
}
String profile = (value != null) ? value.toString() : null;
Assert.state(StringUtils.hasText(profile), "Invalid empty profile");
for (int i = 0; i < profile.length(); i++) {
int codePoint = profile.codePointAt(i);
boolean isAllowedChar = ALLOWED_CHARS.indexOf(codePoint) != -1;
Assert.state(isAllowedChar || Character.isLetterOrDigit(codePoint),
() -> "Profile '%s' must contain a letter, digit or allowed char (%s)".formatted(profile,
Arrays.stream(ALLOWED_CHARS.split("")).collect(Collectors.joining("', '", "'", "'"))));
Assert.state((i > 0 && i < profile.length() - 1) || Character.isLetterOrDigit(codePoint),
() -> "Profile '%s' must start and end with a letter or digit".formatted(profile));
}
}
static ProfilesValidator get(Binder binder) {
return new ProfilesValidator(binder.bind("spring.profiles.validate", Boolean.class).orElse(true));
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free