quarkus: Hibernate-validator won't properly work when using @Observes for ApplicationScoped.class

Describe the bug

When using hibernate-validator on a class containing a @Observes @Initialized(ApplicationScoped.class) method, all the methods containing constraint annotations throw a NullPointerException:

java.lang.NullPointerException: Cannot invoke "javax.validation.Validator.forExecutables()" because "this.validator" is null

	at io.quarkus.hibernate.validator.runtime.interceptor.AbstractMethodValidationInterceptor.validateMethodInvocation(AbstractMethodValidationInterceptor.java:59)
	at io.quarkus.hibernate.validator.runtime.interceptor.MethodValidationInterceptor.validateMethodInvocation(MethodValidationInterceptor.java:17)
	at io.quarkus.hibernate.validator.runtime.interceptor.MethodValidationInterceptor_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
        ...

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

One can reproduce the problem with a QuarkusTest:

@QuarkusTest
class HibernateValidatorTest {

    @Inject
    TestClass testClass;

    @Test
    void test() {
        testClass.call(null); // or testClass.call("");
    }

    @ApplicationScoped
    static final class TestClass {

        void startUp(@Observes @Initialized(ApplicationScoped.class) final Object event) {

        }

        void call(@NotNull final Object o) {

        }

    }
}

Output of uname -a or ver

No response

Output of java -version

No response

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (17 by maintainers)

Most upvoted comments

@i96751414 just to make sure you know, you can make this work by using @Observes Startup instead of the observer you have now. Details can be seen in this guide -> https://quarkus.io/guides/lifecycle#listening-for-startup-and-shutdown-events

@i96751414 expect a fixed version next Wednesday.