Markus Jung created BVAL-222:
--------------------------------
Summary: BValInterceptor not actived when Constrains are only in
superclasses
Key: BVAL-222
URL: https://issues.apache.org/jira/browse/BVAL-222
Project: BVal
Issue Type: Bug
Affects Versions: 3.0.1
Reporter: Markus Jung
Assignee: Markus Jung
This was reported in TomEE by [~neormx] in TOMEE-4449. This seems to be coming
from BVal directly, as the BValExtension does not enable the BValInterceptor
when there are no constraints in the AnnotatedType. superclass + interfaces are
not being considered right now.
Note: placing annotations on the ovewritten methods directly is illegal as per
the spec (see [5.6.5. Method constraints in inheritance
hierarchies|https://jakarta.ee/specifications/bean-validation/3.0/jakarta-bean-validation-spec-3.0#constraintdeclarationvalidationprocess-methodlevelconstraints-inheritance])
As usual, a test says more than 1000 words:
{code:java}
@RunWith(Arquillian.class)
public class CdiConstraintOnlyOnParentClassTest {
@ClassRule
public static ExternalResource allowMyServiceImplType = new
ExternalResource() {
@Override
protected void before() throws Throwable {
BValExtension.setAnnotatedTypeFilter(at -> at.getJavaClass() ==
GreetingServiceImpl.class);
}
@Override
protected void after() {
BValExtension.setAnnotatedTypeFilter(BValExtension.DEFAULT_ANNOTATED_TYPE_FILTER);
}
};
@Inject
private GreetingService service;
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(GreetingService.class, GreetingServiceImpl.class);
}
@Test
public void validationFail() {
Assert.assertThrows(ConstraintViolationException.class, () ->
service.greet(null));
}
public interface GreetingService {
void greet(@NotNull String name);
}
@ApplicationScoped
public static class GreetingServiceImpl implements GreetingService {
@Override
public void greet(String name) {
}
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)