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

Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.fortuna.ical4j.model.TimeZoneRegistryFactory #598

Closed
Ahamed4 opened this issue Sep 21, 2022 · 11 comments
Assignees

Comments

@Ahamed4
Copy link

Ahamed4 commented Sep 21, 2022

I am trying to upgrade the ical4j from v1.0.3 to v3.2.5, once upgrade I am getting below error:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.fortuna.ical4j.model.TimeZoneRegistryFactory

Jave: 11.

@benfortuna
Copy link
Member

If you can provide the full stack trace I may be able to track down the cause.

@benfortuna benfortuna self-assigned this Sep 23, 2022
@Ahamed4
Copy link
Author

Ahamed4 commented Sep 23, 2022

After initial deployed and accessing the application this is error

Caused by: java.lang.LinkageError: loader constraint violation: when resolving method 'org.slf4j.ILoggerFactory org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()' the class loader <domain>.tomcat.servletcontainer.PlugInOverrideClassLoader @75e451d1 of the current class, org/slf4j/LoggerFactory, and the class loader java.net.URLClassLoader @1e54e1fb for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature (org.slf4j.LoggerFactory is in unnamed module of loader<domain>.tomcat.servletcontainer.PlugInOverrideClassLoader @75e451d1, parent loader java.net.URLClassLoader @1e54e1fb; org.slf4j.impl.StaticLoggerBinder is in unnamed module of loader java.net.URLClassLoader @1e54e1fb, parent loader 'app')
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:423)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388)
	at net.fortuna.ical4j.util.Configurator.<clinit>(Configurator.java:54)
	at net.fortuna.ical4j.model.TimeZoneRegistryFactory.<clinit>(TimeZoneRegistryFactory.java:59)

@Ahamed4
Copy link
Author

Ahamed4 commented Sep 23, 2022

After accessing for second time, since due to above error, the class is not initialised getting, NoClassDefFoundError

@benfortuna
Copy link
Member

benfortuna commented Sep 23, 2022

Ok, maybe check the versions of dependencies in your classpath are aligned with those in the gradle.properties:

https://github.com/ical4j/ical4j/blob/master/gradle.properties

It doesn't have to match exactly, but you should have slf4j-api 1.7.x, etc.

@Ahamed4
Copy link
Author

Ahamed4 commented Sep 23, 2022

Yeah let me check and get back

@Ahamed4
Copy link
Author

Ahamed4 commented Sep 23, 2022

Even Changing the slf4j version to 1.7.36(previous 1.7.28) getting same error:

caused by: java.lang.LinkageError: loader constraint violation: when resolving method 'org.slf4j.ILoggerFactory org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()' the class loader <domain>.tomcat.servletcontainer.PlugInOverrideClassLoader @7a10afec of the current class, org/slf4j/LoggerFactory, and the class loader java.net.URLClassLoader @f981737 for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature (org.slf4j.LoggerFactory is in unnamed module of loader <domain>.tomcat.servletcontainer.PlugInOverrideClassLoader @7a10afec, parent loader java.net.URLClassLoader @f981737; org.slf4j.impl.StaticLoggerBinder is in unnamed module of loader java.net.URLClassLoader @f981737, parent loader 'app')
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:423)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388)
	at net.fortuna.ical4j.util.Configurator.<clinit>(Configurator.java:54)
	at net.fortuna.ical4j.model.TimeZoneRegistryFactory.<clinit>(TimeZoneRegistryFactory.java:59)

Have placed the slf4j inside the particular webapp module in build.gradle file in my project

@benfortuna
Copy link
Member

You may also want to check if your web container has any other versions of slf4j in its classpath.

LinkageError can be caused by having the same library loaded in different classloaders, so check your extension libs, etc.

@Ahamed4
Copy link
Author

Ahamed4 commented Sep 26, 2022

I have a doubt here, how to prevent different classloaders to load the same jar(slf). In my case, we need the jar globally across the projectand i could see the second classloader might be from the ical4j(I may be wrong here). Is there any way to restrict the classLoader from ical4j to load slf?

@benfortuna
Copy link
Member

If you are including slf4j in your common jars (e.g. tomcat lib directory) then don't include it with the ical4j dependency in your web app. You should only provide the jar once.

@Ahamed4
Copy link
Author

Ahamed4 commented Sep 26, 2022

U mean, for particular webapp to excluse this slf4j in build.gradle file? If yes, there is no entry in that particular webapp for slf4j jar. Am i missing something?

@benfortuna
Copy link
Member

So when you include ical4j the transitive dependencies such as slf4j will be automatically included. You need to explicitly exclude this dependency (see gradle docs for how to exclude a transitive dependency).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants