Skip to content

Commit

Permalink
Validate default parameter values as well
Browse files Browse the repository at this point in the history
  • Loading branch information
todvora committed Jul 4, 2024
1 parent 581d649 commit 7a865dd
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/main/java/com/github/joschi/jadconfig/JadConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,9 @@ private void processClassField(Object configurationBean, Field field) throws Val
} catch (ParameterException e) {
throw new ParameterException("Couldn't convert value for parameter \"" + parameterName + "\"", e);
}

LOG.debug("Validating parameter {}", parameterName);
final List<Class<? extends Validator<?>>> validators =
new ArrayList<>(Collections.<Class<? extends Validator<?>>>singleton(parameter.validator()));
validators.addAll(Arrays.asList(parameter.validators()));
validateParameter(validators, parameterName, fieldValue);
validateFieldValue(parameterName, parameter, fieldValue);
} else if (fieldValue != null) {
validateFieldValue(parameterName, parameter, fieldValue);
}

LOG.debug("Setting parameter {} to {}", parameterName, fieldValue);
Expand All @@ -204,6 +201,14 @@ private void processClassField(Object configurationBean, Field field) throws Val
}
}

private void validateFieldValue(String parameterName, Parameter parameter, Object fieldValue) throws ValidationException {
LOG.debug("Validating parameter {}", parameterName);
final List<Class<? extends Validator<?>>> validators =
new ArrayList<>(Collections.<Class<? extends Validator<?>>>singleton(parameter.validator()));
validators.addAll(Arrays.asList(parameter.validators()));
validateParameter(validators, parameterName, fieldValue);
}

private String lookupFallbackParameter(Parameter parameter) {
final Optional<String> fallbackValue = Optional.ofNullable(parameter.fallbackPropertyName())
.filter(fallbackName -> !fallbackName.trim().isEmpty())
Expand Down

0 comments on commit 7a865dd

Please sign in to comment.