Chris Westmorland (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f2c38a...
) *updated* an issue
Hibernate Validator (
https://hibernate.atlassian.net/browse/HV?atlOrigin=eyJpIjoiYWMxZGUzMTI5N...
) / Bug (
https://hibernate.atlassian.net/browse/HV-1797?atlOrigin=eyJpIjoiYWMxZGUz...
) HV-1797 (
https://hibernate.atlassian.net/browse/HV-1797?atlOrigin=eyJpIjoiYWMxZGUz...
) Validation on classes with a bidirectional relationship cause stack overflow on 6.1.x (
https://hibernate.atlassian.net/browse/HV-1797?atlOrigin=eyJpIjoiYWMxZGUz...
)
Change By: Chris Westmorland (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f2c38a...
)
We recently upgraded one of our microservices from Spring Boot 2.2 to 2.3 and ran into a
bug with hibernate validator that seems to affect all 6.1.x versions. Here is an example
that reproduces the issue.
```
{code:java} @JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id",
scope = Parent.class)
public class Parent
{
@NotNull
private Long id;
@Valid
private Set<Child> children = new HashSet<>();
// getters and setters
}
@JsonIdentityInfo(
generator = ObjectIdGenerators.PropertyGenerator.class,
property = "id",
scope = Child.class)
public class Child
{
@NotNull
private Long id;
@NotNull
@Valid
private Parent parent;
// getters and setters
}
@RestController
@Validated
public class ValidatorController
{
@GetMapping("/")
public Parent get()
{
final Parent parent = new Parent();
parent.setId(1L);
final Child child = new Child();
child.setId(1L);
child.setParent(parent);
parent.getChildren().add(child);
return parent;
}
@PostMapping("/")
public void post(@Valid @NotNull @RequestBody Parent parent)
{
System.out.println(parent.getId());
}
}
@SpringBootTest
@RunWith(SpringRunner.class)
@AutoConfigureMockMvc
public class ValidatorTest
{
@Autowired
private MockMvc mvc;
@Test
public void test() throws Exception
{
final MvcResult result =
mvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().is2xxSuccessful()).andReturn();
final String json = result.getResponse().getContentAsString();
System.out.println(json);
mvc.perform(post("/").contentType(MediaType.APPLICATION_JSON).content(json))
.andExpect(status().is2xxSuccessful());
}
} {code}
```
This will trigger a stack overflow...
```
{noformat} at
org.hibernate.validator.internal.engine.ValidatorImpl.access$300(ValidatorImpl.java:84)
at
org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.doValidate(ValidatorImpl.java:715)
at
org.hibernate.validator.internal.engine.ValidatorImpl$CascadingValueReceiver.iterableValue(ValidatorImpl.java:675)
at
org.hibernate.validator.internal.engine.valueextraction.IterableValueExtractor.extractValues(IterableValueExtractor.java:24)
at
org.hibernate.validator.internal.engine.valueextraction.IterableValueExtractor.extractValues(IterableValueExtractor.java:14)
at
org.hibernate.validator.internal.engine.valueextraction.ValueExtractorHelper.extractValues(ValueExtractorHelper.java:42)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedContainerElementsForCurrentGroup(ValidatorImpl.java:651)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:598)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:409)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedAnnotatedObjectForCurrentGroup(ValidatorImpl.java:629)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:590)
at
org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:409)
at
org.hibernate.validator.internal.engine.ValidatorImpl.access$300(ValidatorImpl.java:84)
``` {noformat}
(
https://hibernate.atlassian.net/browse/HV-1797#add-comment?atlOrigin=eyJp...
) Add Comment (
https://hibernate.atlassian.net/browse/HV-1797#add-comment?atlOrigin=eyJp...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100141- sha1:76df2fe )