Springboot occassionally occur following errors:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.security.jca.ProviderConfig$ProviderLoader
at java.base/sun.security.jca.ProviderConfig$3.run(ProviderConfig.java:244)
at java.base/sun.security.jca.ProviderConfig$3.run(ProviderConfig.java:238)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/sun.security.jca.ProviderConfig.doLoadProvider(ProviderConfig.java:238)
at java.base/sun.security.jca.ProviderConfig.getProvider(ProviderConfig.java:218)
at java.base/sun.security.jca.ProviderList.getProvider(ProviderList.java:266)
at java.base/sun.security.jca.ProviderList$ServiceList.tryGet(ProviderList.java:511)
at java.base/sun.security.jca.ProviderList$ServiceList$1.hasNext(ProviderList.java:565)
at java.base/javax.crypto.SecretKeyFactory.nextSpi(SecretKeyFactory.java:301)
at java.base/javax.crypto.SecretKeyFactory.<init>(SecretKeyFactory.java:121)
at java.base/javax.crypto.SecretKeyFactory.getInstance(SecretKeyFactory.java:168)
at com.kingbase8.shaded.com.ongres.scram.common.ScramMechanisms.saltedPassword(ScramMechanisms.java:155)
at com.kingbase8.shaded.com.ongres.scram.common.ScramFunctions.saltedPassword(ScramFunctions.java:59)
at com.kingbase8.shaded.com.ongres.scram.client.ScramSession$ClientFinalProcessor.<init>(ScramSession.java:196)
at com.kingbase8.shaded.com.ongres.scram.client.ScramSession$ClientFinalProcessor.<init>(ScramSession.java:163)
at com.kingbase8.shaded.com.ongres.scram.client.ScramSession$ServerFirstProcessor.clientFinalProcessor(ScramSession.java:130)
JDK information as following:
enter image description here
Ah, please try to search the log, it is possible a ExceptionInInitializerError was happened before, so this time the JVM throws NoClassDefFoundError directly because it was failed last time.
Need to get the call stack of the original ExceptionInInitializerError (if it exists) in order to fix this issue.
Related codes and links
https://github.com/openjdk/jdk11u/blob/jdk-11+28/src/java.base/share/classes/sun/security/jca/ProviderConfig.java#L308 - the class ProviderConfig$ProviderLoader was defined inside OpenJDK 11 so it is not likely to a Java classpath issue
https://stackoverflow.com/a/5756989/2412606 - See definition of NoClassDefFoundError here. thanks to #oldpeculier and #jared
For this problem not very clear why occur. in order to fix the problem. we can manual use Security.addSecurity method to load jca or analogous component again. like BouncyCastle. now it work fine for me.
I was using Java 11 and the project was build using Java 1.8. Once I switched to Java 1.8 it worked fine
Related
I have seen this:
java.lang.NoClassDefFoundError: Could not initialize class XXX
And this: Different methodologies for solving bugs that only occur in production
But my question is, given what the first answer says about this problem, how could it be that I could be getting that error on only one of the two places? isn't this a pretty serious error that should prevent the program from compiling in any location? (I properly import the class in the file this error occurs.)
What differences between the two environments should I be looking for?
Other questions about the error I'm getting in QA indicate it could be some nested problem with the class itself, but like I said if that was the case why would it only happen in the QA environment? I can run jmeter load/endurance tests against my program all day long locally and not see this error.
Note, I don't handle the deployments to QA, but is there something I should ask the guy who does? Would run config differences be a potential cause?
The logs in splunk aren't super helpful, here's part of the exception of one instance of the error:
[https-jsse-nio-11402-exec-9] 28 Jun 2021 13:29:45,415+0000 ERROR GenericThrowableMapper [{applicationSystemCode=[removed]-app, clientIP=[removed], clusterId=[removed], containerId=[removed], correlationId=[removed], domainName=[removed], hostName=[removed], messageId=[removed], userId=[removed], webAnalyticsCorrelationId=|}]: java.lang.NoClassDefFoundError: Could not initialize class [removed].CDDConfig
at [removed].execute([removed]AggregationResource.java:77)
at [removed]AggregationResource$$FastClassBySpringCGLIB$$7a8c5a8e.invoke(<generated>)
It then goes on into package classes and all that for a bunch of lines. I add this to ask - maybe there's something else I should try to have it log?
This isn't much more than a spontaneous guess, but judging from experience, I suspect a JDK / JRE version error.
Classic case I witnessed: you compile something on your dev machine with, say, OpenJDK version 8.x.x. You commit / push, the Jenkins CICD pipe starts running, but someone configured its JAVA_HOME to some 11.x version JDK.
-> ClassNotFoundError, NoClassDef, etc.
If you do not do the deployment to QA yourself, can you check what JDK the code has been compiled with? Or ask the guy doing it for that info.
I am doing some maintenance to a JAVA backend written using bundles. When running the code after doing some software upgrade, I get that error at first:
! java.lang.NoSuchMethodError: org.osgi.framework.BundleContext.registerService (Ljava/lang/Class;Lorg/osgi/framework/ServiceFactory;Ljava/util/Dictionary;) Lorg/osgi/framework/ServiceRegistration;
When running it a second time, it gives me the following error:
! java.lang.NoClassDefFoundError: Could not initialize class com.sap.hilo.orchestration.workspace.HiloWorkspaceFactory
Then, it keeps showing the second error for any extra code runs. Any clues how resolve this issue?
Regarding:
java.lang.NoSuchMethodError: org.osgi.framework.BundleContext.registerService
I found an answer to a similar question here: OSGi: servicereference.getBundle().getVersion() - No such method error
In the Import-Package section of the pom.xml file you'll need to change the org.osgi.framework version to at least 1.6 or give it a range [1.6,2.0)
I keep getting java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
The full stacktrace is:
java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:108)
net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:69)
net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:57)
net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:200)
net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:215)
net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:115)
net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:583)
net.sf.jasperreports.engine.JasperRunManager.runToPdf(JasperRunManager.java:455)
net.sf.jasperreports.engine.JasperRunManager.runReportToPdf(JasperRunManager.java:870)
com.evnica.interop.main.ReportServlet.createReport(ReportServlet.java:119)
com.evnica.interop.main.ReportServlet.doGet(ReportServlet.java:96)
com.evnica.interop.main.ReportServlet.service(ReportServlet.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
I have searched for the solution and found a bunch.
Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
JasperReports NoClassDefFoundError exception on net.sf.jasperreports.engine.util.JRStyledTextParser
and about 10 more (this is my first question so I can't enlist them all).
I have tried:
To set java.awt.headless=true.
I did it within code:
static {
System.setProperty("java.awt.headless", "true");
System.out.println(java.awt.GraphicsEnvironment.isHeadless());
}
(returns true as expected).
I did it in JVM Options:
I set CATALINA_OPTS to -Djava.awt.headless=true. Echoes as expected.
It didn't help.
I tested it with.jrxml with DejaVu Sans and included jasperreports-fonts-6.2.2.jar in the path, and I tested it with Sans Serif. I checked which fonts were available to JVM and tested with them. No success.
There were suggestions to check versions of jasperreports jars - I checked it too. I have all the jars of 6.2.2. version:
jasperreports-6.2.2.jar,
jasperreports-fonts-6.2.2.jar,
jasperreports-javaflow-6.2.2.jar.
I use joda-time-2.9.3 (have no idea how it's connected to the problem, but one advice was to use joda; I used it from the beginning anyway), project SDK is java 1.8.0_51 (there was an advice to update to 8 - not relevant as I already use it), and my Tomcat is OK (the absent work folder caused similar problem in one of the cases).
What am I missing?
EDIT:
While debugging I came to a method initializeGrophEnv() in JRGraphEnvInitializer class, which throws a util.graphic.environment.initialization.error:
AVAILABLE_FONT_FACE_NAMES.addAll(Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()));
It's interesting that the method getAvailableFontFamilyNames() in SunGraphicsEnvironment returns a valid array of 274 elements (printscreen from debugger under link):
First of all, thanks everyone for help. You responded so fast, and made me dig deeper =) The problem is solved.
My error was to have both jasperreports-6.2.2.jar and jasperreports-javaflow-6.2.2.jar in the libraries. As you remember, the last method in the stack trace was the initialization of JRBaseFiller. The presence of two jars caused a conflict, as both contain a package net.sf.jasperreports.engine.fill with a JRBaseFiller class in it.
I left the jasperreports-javaflow-6.2.2.jar only. It didn't work on its own. I added two more libraries: jfreechart-1.0.19.jar (previous versions didn't contain all the needed classes) and jcommon-1.0.8. The java.lang.NoClassDefFoundError is gone.
I tried to reproduce the attempt to make a capture of a window following :
Java - Window Image
(2 years old post)
I'm using JNA 3.5.0 and tested the unmodified code under XP and 7 with jre 7, and both failed with the same trace :
Exception in thread "main" java.lang.AbstractMethodError:
com.sun.jna.Structure.getFieldOrder()Ljava/util/List;
at com.sun.jna.Structure.fieldOrder(Structure.java:831)
at com.sun.jna.Structure.getFields(Structure.java:857)
at com.sun.jna.Structure.deriveLayout(Structure.java:983)
at com.sun.jna.Structure.calculateSize(Structure.java:908)
at com.sun.jna.Structure.calculateSize(Structure.java:896)
at com.sun.jna.Structure.allocateMemory(Structure.java:357)
at com.sun.jna.Structure.<init>(Structure.java:191)
at com.sun.jna.Structure.<init>(Structure.java:180)
at com.sun.jna.Structure.<init>(Structure.java:167)
at com.sun.jna.Structure.<init>(Structure.java:159)
at com.sun.jna.platform.win32.WinDef$RECT.<init>(WinDef.java:320)
at Paint.capture(Paint.java:24)
at Paint.<init>(Paint.java:71)
at Paint.main(Paint.java:64)
To reproduce it simply just run :
import com.sun.jna.platform.win32.WinDef.RECT;
public class Test {
public static void main(String[] args) {
RECT rect = new RECT();
}
}
If I understand JNA correctly, com.sun.jna.platform.win32.WinDef should be mapped to a system DLL by default.
It seems that the mapping is not correctly done.
I tried to figure out how to map WinDef to needed dll but couldn't find out how to do this with com.sun.jna.Native.loadLibrary method.
I don't understand why a AbstractMethodError is thrown instead of an UnsatisfiedLinkError, so I'm not sure the library loading is really the problem.
Instanciating com.sun.jna.Structure causes the exception, bug I didn't find any information on wether it could be fixed by a native library loading or it is a bug that has another cause.
I thought it could be Windows rights (admin) that my application doesn't acquire.
Or maybe I have to explicitely precise some pathes to jna so that he can find the dlls (but as I said before, it is no UnsatisfiedLinkError so it shouldn't be that).
If you have any experience with JNA and can give me some advice, please answer me.
Given the stacktrace, the understanding of JNA libraries I acquired so far, hours of searches and javadoc exploring, I obviously missed something that a JNA average user could probably find it (the original post is qualified of "Working example").
By the way, if you have any links or resources about jna (didn't find many), please post them :)
Thanks in advance !
I don't know why but it works for me with JNA 3.4.0.
You can find it on MavenRepository http://mvnrepository.com/artifact/net.java.dev.jna
Thanks for your attention
The first line of the error
Exception in thread "main" java.lang.AbstractMethodError:
nearly always indicates a linkage error, that you're using incompatible versions of something.
In this specific case, it appears that platform.jar file released in JNA 3.5.0 was not properly updated.
We have coded and run a dynamic web application using MAPSERVER(Version 6.0.1) on windows platform using Java Technology. Now, there is need of deploying it on Ubuntu 11.10. We have installed Apache Tomcat 6.0, Mapserver 6.0.1, Apache 2.0, and FWTools-2.0.1(As this package contain all required tools for mapserver if I am not wrong, so I didn't feel any other tools to be installed). We have deployed the war file(and put application without) in Apache Tomcat 's Webapps folder. I even got the index page which dont have code related with mapscript api. But while fetching the other servlet with mapscript we are getting following error...
java.lang.UnsatisfiedLinkError: no mapscript in java.library.path
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
java.lang.Runtime.loadLibrary0(Runtime.java:840)
java.lang.System.loadLibrary(System.java:1047)
edu.umn.gis.mapscript.mapscriptJNI.<clinit>(mapscriptJNI.java:23)
edu.umn.gis.mapscript.mapObj.<init>(mapObj.java:283)
Again while refreshing the browser page where the above error was displayed, I got a change,
java.lang.NoClassDefFoundError: Could not initialize class
edu.umn.gis.mapscript.mapscriptJNI
edu.umn.gis.mapscript.mapObj.<init>(mapObj.java:283)
I searched on net about the above problem. But finally blank. Please, provide idea about the above problem.
I'm not going to explain why you're getting the UnsatisfiedLinkError, but instead I'll explain why you are getting the NoClassDefFoundError when you reload the page.
A NoClassDefFoundError with a message Could not initialize class ... is thrown by the JVM when it attempts to initialize a class that it has already tried and failed to initialize.
The first of your two stacktraces contains the line
edu.umn.gis.mapscript.mapscriptJNI.<clinit>(mapscriptJNI.java:23)
The method name <clinit> denotes the static initializer, of the class mapscriptJNI. So, at the point that the UnsatisfiedLinkError was thrown, the JVM was trying to initialize this class. Looking at the error message, it seems that this static initializer tried to load the native code library mapscript but failed.
This UnsatisfiedLinkError causes the mapscriptJNI class to fail to initialize successfully. The JVM keeps a record of all classes that fail to initialize, and if you attempt to initialize one of those classes again, you'll get a NoClassDefFoundError with a message saying that it could not initialize that class.
When you refresh the page, you end up causing the JVM to attempt to initialize the class mapscriptJNI a second time. Of course, this class failed to initialize the previous time. Your second stacktrace contains exactly the error I've described.
In short, the UnsatisfiedLinkError is the real error here. Fix that and the other one will go away.
I would check the following 2 items:
Is the mapscript.jar file on Tomcat or at least your webapp's classpath? (NoClassDefFoundError is your big clue here)
Is the libmapscript.so on either your LD_LIBRARY_PATH or -Djava.library.path? (UnsatisfiedLinkError since the shared object cannot be found)
Try having a look at this post, near the Running Java Mapscript (on Linux) section.
Hope that helps!