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

Classloading issues with CustomResource #2827

Closed
iocanel opened this issue Feb 23, 2021 · 0 comments · Fixed by #2830 or jenkinsci/kubernetes-client-api-plugin#83
Closed

Classloading issues with CustomResource #2827

iocanel opened this issue Feb 23, 2021 · 0 comments · Fixed by #2830 or jenkinsci/kubernetes-client-api-plugin#83
Assignees

Comments

@iocanel
Copy link
Member

iocanel commented Feb 23, 2021

From: quarkusio/quarkus#15250

2021-02-22 21:07:28,941 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile dev): java.lang.ClassNotFoundException: io.websitecd.operator.crd.WebsiteSpec
	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 io.fabric8.kubernetes.client.CustomResource.getInstantiator(CustomResource.java:309)
	at io.fabric8.kubernetes.client.CustomResource.genericInit(CustomResource.java:337)
	at io.fabric8.kubernetes.client.CustomResource.initSpec(CustomResource.java:117)
	at io.fabric8.kubernetes.client.CustomResource.<init>(CustomResource.java:108)
	at io.websitecd.operator.crd.Website.<init>(Website.java:20)

The problem here seems to be that we make the assumption that TCCL will be responsible to load the class.

How to solve this

  • Since we can really know which classloader may or may not load the class, our safest bet is to use getClass().getClassLoader().
  • Why?
  • Because, most of the time spec/status classes will be either in the same artifact (or a dependency) of the artifact containing the enclosing class.
    So, the classloader that loaded the enclosing class most of the time should be able to also load the spec and status. That should even work in environments like OSGi.

In addition to that we should use TCCL as a fallback mechanism.

@iocanel iocanel self-assigned this Feb 23, 2021
iocanel added a commit to iocanel/kubernetes-client that referenced this issue Feb 23, 2021
iocanel added a commit to iocanel/kubernetes-client that referenced this issue Feb 23, 2021
This was referenced Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment