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

Unable to use ff4j web console in quarkus application: Caused by: java.lang.ClassNotFoundException: org.acme.MyFF4jProvider #487

Open
franden opened this issue Jan 28, 2021 · 3 comments
Labels

Comments

@franden
Copy link

franden commented Jan 28, 2021

If I try to use ff4j web console in a quarkus application, I get following Exception on startup of the FF4jDispatcherServlet that the class of my FF4jProvider is not known:

Caused by: java.lang.ClassNotFoundException: org.acme.MyFF4jProvider
        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:428)
        at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:378)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at org.ff4j.web.FF4jServlet.initializeFF4J(FF4jServlet.java:152)
        ... 29 more

The reason is this line:

Class<?> c = Class.forName(className);

As described here: "Class.forName() without a CL is often problematic."

Please change this line to use the current classlaoder: Class<?> c = Thread.currentThread().getContextClassLoader().loadClass(className);

@clun
Copy link
Collaborator

clun commented Feb 3, 2021

You are right will work on it over the week-end would be great to have a quarkus sample in the pool

@franden
Copy link
Author

franden commented Feb 10, 2021

Similar Issue happens if custom flipping strategy is used. In this case the custom class can not be loaded (ClassNotFoundException):

Class<FlippingStrategy> clazz = (Class<FlippingStrategy>) (classLoader == null ? Class.forName(className) : classLoader.loadClass(className));

it could be changed to:
Class<FlippingStrategy> clazz = (Class<FlippingStrategy>) (classLoader == null ? Thread.currentThread().getContextClassLoader().loadClass(className) : classLoader.loadClass(className));

Currently I am using: MappingUtil.setClassLoader(Thread.currentThread().getContextClassLoader()); as workaround

@franden
Copy link
Author

franden commented Feb 10, 2021

I guess the similar issue will happen everywhere where Class.forName(className) is used to load custom code from
e.g:

Constructor<?> constr = Class.forName(pType).getConstructor(String.class, String.class);

image

@clun clun added the bug label Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants