Skip to main content



      Home
Home » Eclipse Projects » Eclipse Adoptium Incubator » Classloader issue(ClassCastException with AppClassLoader and URLClassLoader in OpenJDK 17)
Classloader issue [message #1872168] Thu, 24 October 2024 09:03
Eclipse UserFriend
Hello Team,

I need to migrate our legacy application from java8 to java17. While running the application, I encountered the following exception with OpenJDK 17. This worked fine with Java 8, but the new class loader mechanism under the module system is causing issues. What should be the solution for this? I am stuck for so many days, nowhere getting any solutions. Please guide me.
java -version
openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment Temurin-17.0.11+9 (build 17.0.11+9)
OpenJDK 64-Bit Server VM Temurin-17.0.11+9 (build 17.0.11+9, mixed mode, sharing)

Exception in thread "main" java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap')
at sentinel.command.SentinelBoot.addToClassPath(SentinelBoot.java:194)
at sentinel.command.SentinelBoot.initClassPath(SentinelBoot.java:63)
at sentinel.command.SentinelStarter.initStarter(SentinelStarter.java:54)
at sentinel.command.TrkServer.main(TrkServer.java:48)

Sharing few code snippets for reference:
URLClassLoader sysloader = (URLClassLoader)ClassLoader.getSystemClassLoader();
Class<URLClassLoader> sysclass = URLClassLoader.class;
Method method = sysclass.getDeclaredMethod("addURL", parameters);
method.setAccessible(true);
method.invoke(sysloader, new Object[]{u});

Thanks in advance!
Previous Topic:Difference between AdoptJDK and OracleJDK
Goto Forum:
  


Current Time: Tue May 13 08:15:14 EDT 2025

Powered by FUDForum. Page generated in 0.13272 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top