Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hibernate Validator - @Valid Object causes CNFE #12443

Closed
Postremus opened this issue Oct 1, 2020 · 4 comments · Fixed by #12627
Closed

Hibernate Validator - @Valid Object causes CNFE #12443

Postremus opened this issue Oct 1, 2020 · 4 comments · Fixed by #12627
Labels
area/hibernate-validator Hibernate Validator kind/bug Something isn't working
Milestone

Comments

@Postremus
Copy link
Member

Postremus commented Oct 1, 2020

Describe the bug
I noticed an odd behaviour in one of my apps during dev mode.
mvn clean install runs sucessfully on the project.

@Valid Object causes a CNFE for javax.servlet.Filter. The project did not use servlets however.

After a bit of debugging, I found this place in the Hibernate Validator extension:

private static void contributeClass(Set<DotName> classNamesCollector, IndexView indexView, DotName className) {
classNamesCollector.add(className);
for (ClassInfo subclass : indexView.getAllKnownSubclasses(className)) {
if (Modifier.isAbstract(subclass.flags())) {
// we can avoid adding the abstract classes here: either they are parent classes
// and they will be dealt with by Hibernate Validator or they are child classes
// without any proper implementation and we can ignore them.
continue;
}
classNamesCollector.add(subclass.name());

It was adding the JaxRsMetricsFilter to the set of classes that need validation. In turn, this loaded at runtime the servlet Filter class.

Removing the @Valid Object constraint solved the problem for me.

Expected behavior
Quarkus should not blindly add every class it finds as possible class that needs validation. E.g. most of the quarkus internal classes may never need to be validated in user applications.

Actual behavior

2020-10-01 12:40:16,931 ERROR [io.qua.run.boo.StartupActionImpl] (Quarkus Main Thread) Error running Quarkus: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.quarkus.runner.bootstrap.StartupActionImpl$3.run(StartupActionImpl.java:134)
        at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ExceptionInInitializerError
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at java.base/java.lang.Class.newInstance(Class.java:584)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:60)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:38)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:106)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
        ... 6 more
Caused by: java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:288)
        ... 15 more
Caused by: java.lang.NoClassDefFoundError: javax/servlet/Filter
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
        at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:400)
        at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:363)
        at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:406)
        at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:363)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:398)
        at io.quarkus.deployment.steps.HibernateValidatorProcessor$build-642046765.deploy_0(HibernateValidatorProcessor$build-642046765.zig:4092)
        at io.quarkus.deployment.steps.HibernateValidatorProcessor$build-642046765.deploy(HibernateValidatorProcessor$build-642046765.zig:40)
        at io.quarkus.runner.ApplicationImpl.<clinit>(ApplicationImpl.zig:202)
        ... 15 more
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:406)
        at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:363)
        ... 26 more

To Reproduce

Link to a small reproducer (preferably a Maven project if the issue is not Gradle-specific).

Or attach an archive containing the reproducer to the issue.
metrics-cnfe-filter.zip

Steps to reproduce the behavior:

  1. Download the attached reproducer
  2. mvnw quarkus:dev
  3. Look into the console, quarkus does not start, and the exception is printed.

Environment (please complete the following information):

  • Output of uname -a or ver: MSYS_NT-10.0 NANB7NLNVP2 2.10.0(0.325/5/3) 2018-06-13 23:34 x86_64 Msys
  • Quarkus version or git rev: 1.8.1.Final
  • Build tool (ie. output of mvnw --version or gradlew --version):
    Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
    Maven home: C:\Users\mnp.m2\wrapper\dists\apache-maven-3.6.3-bin\1iopthnavndlasol9gbrbg6bf2\apache-maven-3.6.3
    Java version: 11.0.7, vendor: Azul Systems, Inc., runtime: C:\eclipse\tools\zulu11.39.15-ca-jdk11.0.7-win_x64
    Default locale: de_DE, platform encoding: Cp1252
    OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
@Postremus Postremus added the kind/bug Something isn't working label Oct 1, 2020
@quarkusbot quarkusbot added the area/hibernate-validator Hibernate Validator label Oct 1, 2020
@quarkusbot
Copy link

/cc @gsmet

@gsmet
Copy link
Member

gsmet commented Oct 1, 2020

So we can add a safeguard for this, for sure. But keep in mind that having @Valid on Object will cause issues. We need to gather the types that will be validated by Hibernate Validator, it cannot be random ones.

@Postremus
Copy link
Member Author

Yeah, quarkus needs a list of all types. but a safeguard might help in case someone else has this problem.

@gsmet
Copy link
Member

gsmet commented Oct 9, 2020

@Postremus could you check #12627 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-validator Hibernate Validator kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants