-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finatra-validation: Fix Validator for Case Classes with Other Fields
Problem The `Validator` throws an `IndexOutOfBoundsException` when trying to validate a case class which contains fields that are not set via constructor parameters. This is because of `Validator`'s use of `AnnotationUtils`, and that in this scenario, `Validator` is breaking the contract of how it should be used. `Validator` passed in an array of fields returned from `getDeclaredFields`, which will return ALL fields. `AnnotationUtils` is only expecting a subset of the list of parameters that it would find via the constructor. The two don't match and so an exception occurs. Solution After consultation with the team, we do not want to change `AnnotationUtils` at this time. So, we instead fix `Validator` to abide by the contract of the method and pass in the appropriate constructor parameters, rather than ALL fields. So we swap out the use of `getDeclaredFields` with a retrieval of parameters based on the first constructor. JIRA Issues: CSL-10170 Differential Revision: https://phabricator.twitter.biz/D549253
- Loading branch information
1 parent
d5e5a13
commit bb342c0
Showing
4 changed files
with
29 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters