payload: {"action":"opened","issue":{"url":"https://api.github.com/repos/spring-projects/spring-framework/issues/24034","repository_url":"https://api.github.com/repos/spring-projects/spring-framework","labels_url":"https://api.github.com/repos/spring-projects/spring-framework/issues/24034/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-framework/issues/24034/comments","events_url":"https://api.github.com/repos/spring-projects/spring-framework/issues/24034/events","html_url":"https://github.com/spring-projects/spring-framework/issues/24034","id":525199039,"node_id":"MDU6SXNzdWU1MjUxOTkwMzk=","number":24034,"title":"Potential issue with validations in a service method","user":{"login":"hadjiski","id":19952527,"node_id":"MDQ6VXNlcjE5OTUyNTI3","avatar_url":"https://avatars2.githubusercontent.com/u/19952527?v=4","gravatar_id":"","url":"https://api.github.com/users/hadjiski","html_url":"https://github.com/hadjiski","followers_url":"https://api.github.com/users/hadjiski/followers","following_url":"https://api.github.com/users/hadjiski/following{/other_user}","gists_url":"https://api.github.com/users/hadjiski/gists{/gist_id}","starred_url":"https://api.github.com/users/hadjiski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadjiski/subscriptions","organizations_url":"https://api.github.com/users/hadjiski/orgs","repos_url":"https://api.github.com/users/hadjiski/repos","events_url":"https://api.github.com/users/hadjiski/events{/privacy}","received_events_url":"https://api.github.com/users/hadjiski/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2019-11-19T18:55:51Z","updated_at":"2019-11-19T18:55:51Z","closed_at":null,"author_association":"NONE","body":"<!--\r\n!!! For Security Vulnerabilities, please go to https://pivotal.io/security !!!\r\n-->\r\n**Affects:** Spring Framework 5.1\r\n\r\n---\r\n<!--\r\nThanks for taking the time to create an issue. Please read the following:\r\n\r\n- Questions should be asked on Stack Overflow.\r\n- For bugs, specify affected versions and explain what you are trying to do.\r\n- For enhancements, provide context and describe the problem.\r\n\r\nIssue or Pull Request? Create only one, not both. GitHub treats them as the same.\r\nIf unsure, start with an issue, and if you submit a pull request later, the\r\nissue will be closed as superseded.\r\n-->\r\nHaving a `Service `and `Validated` annotated class makes it possible to add validation annotations to its service methods (e.g. as described in this [tutorial](https://reflectoring.io/bean-validation-with-spring-boot/#validating-input-to-a-spring-service-method)).\r\n\r\nThis works fine:\r\n```java \r\n@Service\r\n@Validated\r\nclass ValidatingService {\r\n\r\n    void validateInput(@Valid @NotNull String input1,\r\n                       @Valid @NotEmpty Map<String, String> input2) {\r\n      // input1 is for sure not null and input2 is for sure not empty\r\n    }\r\n\r\n}\r\n```\r\nBut this not:\r\n\r\n```java\r\n@Service\r\n@Validated\r\nclass ValidatingService {\r\n\r\n    void validateInput(String input1, Map<String, String> input2) {\r\n       if (something)\r\n         internalValidateInput(input1);\r\n       else\r\n         internalValidateInput(input2);\r\n    }\r\n    private void internalValidateInput(@Valid @NotNull String input) {\r\n      // input is not validated at all, why?\r\n    }\r\n\r\n    private void internalValidateInput(@Valid @NotEmpty Map<String, String> input) {\r\n      // input is not validated at all, why?\r\n    }\r\n\r\n}\r\n```\r\nThe simple and working first approach cannot be used, since the use case is that in `validateInput` either only one of the inputs is provided, thus the other one is null/empy and based on the `something` strategy either the one or the other should be validated, but never both together.\r\nThe second approach with `internalValidateInput` methods is just not working.\r\n\r\nNevertheless when the validation is extracted in a separate validation service class it works, but it looks weird:\r\n```java\r\n@Service\r\nclass ValidatingService {\r\n\r\n    @Autowired\r\n    private CustomValidator validator;\r\n\r\n    void validateInput(String input1, Map<String, String> input2) {\r\n       if (something)\r\n         internalValidateInput(input1);\r\n       else\r\n         internalValidateInput(input2);\r\n    }\r\n    private void internalValidateInput(String input) {\r\n      this.validator.validate(input);\r\n      // now the validation works and input is for sure not null\r\n    }\r\n\r\n    private void internalValidateInput(Map<String, String> input) {\r\n      this.validator.validate(input);\r\n      // now the validation works and input is for sure not empty\r\n    }\r\n\r\n}\r\n\r\n@Service\r\n@Validated\r\nclass CustomValidator {\r\n\r\n    void validate(@Valid @NotNull String input) {\r\n        // remains an empty implementation, kind of dirty hack :)?\r\n    }\r\n    void validate(@Valid @NotEmpty Map<String, String> input) {\r\n        // remains an empty implementation, kind of dirty hack :)?    }\r\n}\r\n```"}}
other: {"actor":{"display_login":"hadjiski"}}