-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config processing with lazy error handling #127
base: main
Are you sure you want to change the base?
Config processing with lazy error handling #127
Conversation
I have adapted the behaviour to match the eager processing mode. The lazy method now doesn't return any result, the return type is void. The outcome of the processing is either configured beans or a ValidationException, aggregating all the errors and providing access to the underlying ProcessingResponse, if the caller wants to handle the errors in a specific way. This is how the exception looks now, aggregating three missing properties: The only change from the caller perspective is to switch from |
import static com.github.joschi.jadconfig.ReflectionUtils.getAllFields; | ||
import static com.github.joschi.jadconfig.ReflectionUtils.getAllMethods; | ||
import static com.github.joschi.jadconfig.ReflectionUtils.invokeMethodsWithAnnotation; | ||
import static com.github.joschi.jadconfig.ReflectionUtils.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the wildcard import.
} | ||
|
||
ProcessingResponse doProcessFailingLazily() throws RepositoryException { | ||
ProcessingResponse response = new ProcessingResponse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The response
can be final.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rewritten this block to avoid all mutations of the ProcessingResponse.
if (parameter != null) { | ||
LOG.debug("Processing field {}", parameter); | ||
private Map<String, Exception> processClassFieldsFailingLazily(Object configurationBean, Field[] fields) { | ||
Map<String, Exception> fieldProcessingProblems = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field can be final.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -242,6 +293,27 @@ private void invokeValidatorMethods(Object configurationBean, Method[] methods) | |||
} | |||
} | |||
|
|||
private Map<String, Exception> invokeValidatorMethodsFailingLazily(Object configurationBean, Method[] methods) { | |||
Map<String, Exception> problems = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field can be final.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
public void validate() throws ValidationException { | ||
public void myCustomValidatorMethod() throws ValidationException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for renaming this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the method is string-matched later in the test. "validate" seems like too vague name and it's not really clear where it is coming from. Changing the name to "myCustomValidatorMethod" makes the connection clear and and removes any doubts.
// TODO: should we distinct between field processing problem and validation method? | ||
// TODO: should we include class name of the bean or not? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these still open tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, removed the todo and simplified the code
Fixes #126
Notes for Reviewers