Skip to content

Commit 818dd8d

Browse files
committed
Update to Hibernate Validator 9.1
1 parent 4028677 commit 818dd8d

File tree

6 files changed

+51
-36
lines changed

6 files changed

+51
-36
lines changed

extensions/hibernate-validator/deployment/src/test/java/io/quarkus/hibernate/validator/test/CustomConfigurationViaBeansTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ public void testCustomConfigurationViaBeans() {
5757
assertThat(hibernateValidatorFactory.getScriptEvaluatorFactory()).isInstanceOf(MyScriptEvaluatorFactory.class);
5858
assertThat(hibernateValidatorFactory.getGetterPropertySelectionStrategy())
5959
.isInstanceOf(MyGetterPropertySelectionStrategy.class);
60-
// Waiting for https://hibernate.atlassian.net/browse/HV-1841 to be released
61-
//assertThat(hibernateValidatorFactory.getPropertyNodeNameProvider())
62-
// .isInstanceOf(MyPropertyNodeNameProvider.class);
60+
assertThat(hibernateValidatorFactory.getPropertyNodeNameProvider())
61+
.isInstanceOf(MyPropertyNodeNameProvider.class);
6362
}
6463

6564
@ApplicationScoped

extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/interceptor/AbstractMethodValidationInterceptor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import jakarta.validation.Validator;
1717
import jakarta.validation.executable.ExecutableValidator;
1818

19+
import org.hibernate.validator.path.RandomAccessPath;
20+
1921
/**
2022
* NOTE: this is a copy of the interceptor present in hibernate-validator-cdi.
2123
* For now, I prefer not depending on this artifact but this might change in the
@@ -153,6 +155,9 @@ private String getMessage(Member member, Object[] args, Set<? extends Constraint
153155
}
154156

155157
private Path.Node getLeafNode(ConstraintViolation<?> constraintViolation) {
158+
if (constraintViolation.getPropertyPath() instanceof RandomAccessPath randomAccessPath) {
159+
return randomAccessPath.getLeafNode();
160+
}
156161
Iterator<Path.Node> nodes = constraintViolation.getPropertyPath().iterator();
157162
Path.Node leafNode = null;
158163
while (nodes.hasNext()) {
Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
11
package io.quarkus.hibernate.validator.runtime.jaxrs;
22

3-
import java.util.Iterator;
4-
53
import jakarta.validation.ConstraintViolation;
64
import jakarta.validation.ElementKind;
75
import jakarta.validation.Path.Node;
86

7+
import org.hibernate.validator.path.RandomAccessPath;
98
import org.jboss.resteasy.api.validation.ConstraintType;
109
import org.jboss.resteasy.resteasy_jaxrs.i18n.Messages;
1110
import org.jboss.resteasy.spi.validation.ConstraintTypeUtil;
1211

1312
public class ConstraintTypeUtil20 implements ConstraintTypeUtil {
1413

15-
@Override
16-
public ConstraintType.Type getConstraintType(Object o) {
17-
if (!(o instanceof ConstraintViolation)) {
18-
throw new RuntimeException(Messages.MESSAGES.unknownObjectPassedAsConstraintViolation(o));
19-
}
20-
ConstraintViolation<?> v = ConstraintViolation.class.cast(o);
21-
22-
Iterator<Node> nodes = v.getPropertyPath().iterator();
23-
Node firstNode = nodes.next();
14+
public static final ConstraintTypeUtil INSTANCE = new ConstraintTypeUtil20();
2415

25-
switch (firstNode.getKind()) {
26-
case BEAN:
27-
return ConstraintType.Type.CLASS;
28-
case CONSTRUCTOR:
29-
case METHOD:
30-
Node secondNode = nodes.next();
16+
private ConstraintTypeUtil20() {
17+
}
3118

32-
if (secondNode.getKind() == ElementKind.PARAMETER || secondNode.getKind() == ElementKind.CROSS_PARAMETER) {
33-
return ConstraintType.Type.PARAMETER;
34-
} else if (secondNode.getKind() == ElementKind.RETURN_VALUE) {
35-
return ConstraintType.Type.RETURN_VALUE;
36-
} else {
37-
throw new RuntimeException(Messages.MESSAGES.unexpectedPathNodeViolation(secondNode.getKind()));
19+
@Override
20+
public ConstraintType.Type getConstraintType(Object o) {
21+
if (o instanceof ConstraintViolation<?> v) {
22+
if (v.getPropertyPath() instanceof RandomAccessPath randomAccessPath) {
23+
switch (randomAccessPath.getRootNode().getKind()) {
24+
case BEAN:
25+
return ConstraintType.Type.CLASS;
26+
case CONSTRUCTOR:
27+
case METHOD:
28+
Node secondNode = randomAccessPath.getNode(1);
29+
30+
if (secondNode.getKind() == ElementKind.PARAMETER
31+
|| secondNode.getKind() == ElementKind.CROSS_PARAMETER) {
32+
return ConstraintType.Type.PARAMETER;
33+
} else if (secondNode.getKind() == ElementKind.RETURN_VALUE) {
34+
return ConstraintType.Type.RETURN_VALUE;
35+
} else {
36+
throw new RuntimeException(Messages.MESSAGES.unexpectedPathNodeViolation(secondNode.getKind()));
37+
}
38+
case PROPERTY:
39+
return ConstraintType.Type.PROPERTY;
40+
case CROSS_PARAMETER:
41+
case PARAMETER:
42+
case RETURN_VALUE:
43+
case CONTAINER_ELEMENT: // we shouldn't encounter these element types at the root
44+
default:
45+
throw new RuntimeException(
46+
Messages.MESSAGES.unexpectedPathNode(randomAccessPath.getRootNode().getKind()));
3847
}
39-
case PROPERTY:
40-
return ConstraintType.Type.PROPERTY;
41-
case CROSS_PARAMETER:
42-
case PARAMETER:
43-
case RETURN_VALUE:
44-
case CONTAINER_ELEMENT: // we shouldn't encounter these element types at the root
45-
default:
46-
throw new RuntimeException(Messages.MESSAGES.unexpectedPathNode(firstNode.getKind()));
48+
}
4749
}
50+
throw new RuntimeException(Messages.MESSAGES.unknownObjectPassedAsConstraintViolation(o));
4851
}
4952
}

extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyReactiveViolationExceptionMapper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import jakarta.ws.rs.ext.ExceptionMapper;
2020
import jakarta.ws.rs.ext.Provider;
2121

22+
import org.hibernate.validator.path.RandomAccessPath;
2223
import org.jboss.resteasy.reactive.common.util.ServerMediaType;
2324
import org.jboss.resteasy.reactive.server.core.CurrentRequestManager;
2425
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;
@@ -57,6 +58,11 @@ private boolean hasReturnValueViolation(Set<ConstraintViolation<?>> violations)
5758
}
5859

5960
private boolean isReturnValueViolation(ConstraintViolation<?> violation) {
61+
if (violation.getPropertyPath() instanceof RandomAccessPath randomAccessPath) {
62+
return randomAccessPath.getRootNode().getKind() == ElementKind.METHOD
63+
&& randomAccessPath.getNode(1).getKind() == ElementKind.RETURN_VALUE;
64+
}
65+
6066
Iterator<Path.Node> nodes = violation.getPropertyPath().iterator();
6167
Path.Node firstNode = nodes.next();
6268

extensions/hibernate-validator/runtime/src/main/java/io/quarkus/hibernate/validator/runtime/jaxrs/ResteasyViolationExceptionImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.quarkus.hibernate.validator.runtime.jaxrs;
22

3+
import java.io.Serial;
34
import java.util.List;
45
import java.util.Set;
56

@@ -20,6 +21,7 @@
2021
* while a violation on the parameters of a REST endpoint call is a client error (HTTP 400).
2122
*/
2223
public class ResteasyViolationExceptionImpl extends ResteasyViolationException {
24+
@Serial
2325
private static final long serialVersionUID = 657697354453281559L;
2426

2527
public ResteasyViolationExceptionImpl(final Set<? extends ConstraintViolation<?>> constraintViolations,
@@ -29,7 +31,7 @@ public ResteasyViolationExceptionImpl(final Set<? extends ConstraintViolation<?>
2931

3032
@Override
3133
public ConstraintTypeUtil getConstraintTypeUtil() {
32-
return new ConstraintTypeUtil20();
34+
return ConstraintTypeUtil20.INSTANCE;
3335
}
3436

3537
@Override

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<bytebuddy.version>1.17.6</bytebuddy.version> <!-- version controlled by Hibernate ORM's needs -->
7878
<hibernate-models.version>1.0.1</hibernate-models.version> <!-- version controlled by Hibernate ORM's needs -->
7979
<hibernate-reactive.version>3.1.3.Final</hibernate-reactive.version> <!-- highly sensitive to Hibernate ORM upgrades -->
80-
<hibernate-validator.version>9.0.1.Final</hibernate-validator.version>
80+
<hibernate-validator.version>9.1.0.Alpha2</hibernate-validator.version>
8181
<hibernate-search.version>8.1.2.Final</hibernate-search.version>
8282
<hibernate-tools.version>7.1.1.Final</hibernate-tools.version>
8383

0 commit comments

Comments
 (0)