java.lang.LinkageError --- json-lib -- issue? - jboss

java.lang.LinkageError: Failed to link net/sf/json/JSONException
(Module "MYAPP:lib" from local module loader #4c3e4790 (finder: local
module finder #38cccef (roots:
C:\MYAPPS\EAP-6.4.0\jboss-eap-6.4\modules,C:\MYAPPS\EAP-6.4.0\jboss-eap-6.4\modules\system\layers\base,C:\MYAPPS\EAP-6.4.0\jboss-eap-6.4,C:\MYAPP\Utils\JBossUtils\VLSEnv\VLS1,C:\MYAPP,C:\,C:\MYAPP\Utils\JBossUtils\VLSEnv\VLS1\VLS\bin)))
2017-02-01 02:59:08:450 package1.fusion [272396945]
java.lang.LinkageError: Failed to link net/sf/json/JSONException
(Module "MYAPP:lib" from local module loader #4c3e4790 (finder: local
module finder #38cccef (roots:
C:\MYAPPS\EAP-6.4.0\jboss-eap-6.4\modules,C:\MYAPPS\EAP-6.4.0\jboss-eap-6.4\modules\system\layers\base,C:\MYAPPS\EAP-6.4.0\jboss-eap-6.4,C:\MYAPP\Utils\JBossUtils\VLSEnv\VLS1,C:\MYAPP,C:\,C:\MYAPP\Utils\JBossUtils\VLSEnv\VLS1\VLS\bin)))
we are using an older version of json-lib, is the above problem due to that ?

LinkageError is what you'll get in a classic case where you have a class C loaded by more than one classloader and those classes are being used together in the same code (compared, cast, etc). It doesn't matter if it is the same Class name or even if it's loaded from the identical jar - a Class from one classloader is always treated as a different Class if loaded from another classloader.
This can be happened when you included a library twice. See the link:
https://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/beta422/html/Class_Loading_and_Types_in_Java-LinkageErrors___Making_Sure_You_Are_Who_You_Say_You_Are.html

Related

Linkage error when running groovy script - loader constraint violation in interface itable initialization for class org.apache.xerces.dom.NodeImpl

I've created a groovy script that uses an external Java API (the IBM EWM Build toolkit) to get various attributes of work items for the tool. I'm pulling this external set of libraries using groovy's -cp claspath switch. I'm running into a conflict between the classes used by this toolkit and the internal groovy XML parsing classes:
Caught: java.lang.LinkageError: loader constraint violation in interface itable initialization for class org.apache.xerces.dom.NodeImpl: when selecting method 'org.w3c.dom.NodeList org.w3c.dom.Node.getChildNodes()' the class loader 'bootstrap' for super interface org.w3c.dom.Node, and the class loader org.codehaus.groovy.tools.RootLoader #326de728 of the selected method's abstract class, org.apache.xerces.dom.NodeImpl have different Class objects for the type org.w3c.dom.NodeList used in the signature (org.w3c.dom.Node is in module java.xml of loader 'bootstrap'; org.apache.xerces.dom.NodeImpl is in unnamed module of loader org.codehaus.groovy.tools.RootLoader #326de728, parent loader 'app')
[2022-03-03T13:46:14.198Z] java.lang.LinkageError: loader constraint violation in interface itable initialization for class org.apache.xerces.dom.NodeImpl: when selecting method 'org.w3c.dom.NodeList org.w3c.dom.Node.getChildNodes()' the class loader 'bootstrap' for super interface org.w3c.dom.Node, and the class loader org.codehaus.groovy.tools.RootLoader #326de728 of the selected method's abstract class, org.apache.xerces.dom.NodeImpl have different Class objects for the type org.w3c.dom.NodeList used in the signature (org.w3c.dom.Node is in module java.xml of loader 'bootstrap'; org.apache.xerces.dom.NodeImpl is in unnamed module of loader org.codehaus.groovy.tools.RootLoader #326de728, parent loader 'app')
The problem isn't in my own code, but in some of the API calls I'm making to the external library that call the conflicting class. Is there any way I can get groovy to recognize the external library in this instance rather than the internal one loaded by RootLoader?

Debugging OfBiz in Eclipse gives MissingResourceException

I downloaded the OfBiz Java application and the following line throws an MissingResourceException:
ResourceBundle res = ResourceBundle.getBundle(settingsResourceName);
The value of settingsResourceName is "cache", but I cannot find any file called cache.properties or cache_en.properties.
Where should I be looking? I'm new to Java. All my research on SO says there should be such a file.
I imported OfBiz in Eclipse using the Import menu option and selecting Existing Project from File System (I'm not in front of my dev machine so I don't remember the exact wording). But I chose the root folder of the downloaded OfBiz.
I then added the appropriate VM Arguments in the Run Configuration to get it to run properly at least. And that's it, on the first Run I got the above error. I think it has to do with a missing class path but I don't know what to add to class path.
Here is the stack trace:
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.ofbiz.base.util.Debug.<clinit>(Debug.java:68)
at org.apache.ofbiz.base.container.ContainerLoader.load(ContainerLoader.java:61)
at org.apache.ofbiz.base.start.StartupControlPanel.loadStartupLoaders(StartupControlPanel.java:202)
at org.apache.ofbiz.base.start.StartupControlPanel.start(StartupControlPanel.java:69)
at org.apache.ofbiz.base.start.Start.main(Start.java:84)
Caused by: java.util.MissingResourceException: Can't find bundle for base name cache, locale en
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:773)
at org.apache.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:174)
at org.apache.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:170)
at org.apache.ofbiz.base.util.cache.UtilCache.setPropertiesParams(UtilCache.java:166)
at org.apache.ofbiz.base.util.cache.UtilCache.<init>(UtilCache.java:124)
at org.apache.ofbiz.base.util.cache.UtilCache.createUtilCache(UtilCache.java:769)
at org.apache.ofbiz.base.util.UtilProperties.<clinit>(UtilProperties.java:75)
... 5 more
UPDATE:
My mistake, I found two files both called cache.properties in the following folders:
ofbiz-trunk/build/resources/main
ofbiz-trunk/framework/base/config
But these are folders, not packages. I tried putting them in the .classpath but that did not work, I still kept getting the same error.
As suspected, I knew it was because of a missing reference to a class path. After looking at a section on this page: http://www.opensourcestrategies.com/ofbiz/ofbiz_eclipse.php, I learned that I was supposed to go to the Java Build Path and in the Libraries tab, click on Add Class Folder, then point that to ofbiz-trunk/framework/base/config. Which is where I have one of the cache.properties files.

IKVM - getResourceAsStreams returns null

after compiling a Java library with IKVM into an DLL, I get the following error:
getResourceAsStream("path/to/resource.file") == null"
the library tries to load a Java resouce from the own jar file with the following code:
Thread.currentThread().getContextClassLoader().getResourceAsStream("path/to/resource.file")
as workaround I tried to copy the resouce file into the main directory of my .NET project and call ikvmc with the resource parameter:
ikvmc java-library.jar -target:library -resouce:/path/to/resource.file=resource.file
the strange thing is that the resulting DLL includes a resource.jar containing just an empty directory strukture /path/to/resource.file where resource.file is not the file, but just another empty directory
is there a way to compile Java libraries with ikvmc into DLLs, where the Java code reads resource files with ContextClassLoader.getResourceAsStream()?
The problem was caused by the decission on the class loader. The Java library uses the context class loader:
Thread.currentThread().getContextClassLoader()
In IKVM it seems that this is the general class loader used for the entire .NET runtime. This one is not able to load resources from JAR files. When changing the Java library to use the same class loader that loaded the class containing the resource loading code, the resources are loaded corretly with IKVM as well:
ClassLoader currentClassLoader = MyClass.class.getClassLoader();
URL url = currentClassLoader.getResource("resource/name");

NetBeans and JBoss

I am reading this tutorial http://www.tutorialspoint.com/ejb/index.htm. I have installed NetBeans IDE 8.0.2 and JBoss 5 server. And I have a problem with this part of the tutorial http://www.tutorialspoint.com/ejb/ejb_create_application.htm with jndi.properties file. I don't understand where should i put it? I have put it here C:\Users\Mimo\Documents\NetBeansProjects\EjbTester\jndi.properties in my EjbTester project and I get the following exceptions.
run:
java.io.FileNotFoundException: C:\Users\Mimo\Documents\NetBeansProjects\EjbTester\jndi.properties (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.(FileInputStream.java:138)
at java.io.FileInputStream.(FileInputStream.java:93)
at com.tutorialspoint.test.EJBTester.(EJBTester.java:25)
at com.tutorialspoint.test.EJBTester.main(EJBTester.java:39)
Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.tutorialspoint.test.EJBTester.testStatelessEjb(EJBTester.java:53)
at com.tutorialspoint.test.EJBTester.main(EJBTester.java:41)
Thanks for all your help!
Right click on project name in Project explorer window and select empty file name is jndi.properties and add info it... its work

IllegalAccessError throwing in linux ( suse 10)

enter code herewe are using c3p0 jar for databse pooling. Now from c3p0 code, the following exception is comming
Caused by: java.lang.IllegalAccessError: tried to access class com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource$1 from class com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.setUpPropertyEvents(AbstractPoolBackedDataSource.java:74)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.(AbstractPoolBackedDataSource.java:63)
at com.mchange.v2.c3p0.ComboPooledDataSource.(ComboPooledDataSource.java:109)
at com.mchange.v2.c3p0.ComboPooledDataSource.(ComboPooledDataSource.java:105)
Now in AbstractPoolBackedDataSource.java (line 74)
PropertyChangeListener l = new PropertyChangeListener()
PropertyChangeListener l = new PropertyChangeListener()
{
public void propertyChange( PropertyChangeEvent evt )
{ resetPoolManager(); }
};
So, PropertyChangeListener is the inner class here .. AbstractPoolBackedDataSource$1
PropertyChangeListener is a java class java.beans.PropertyChangeListener !!
What can be the reason ? This is only happening in linux(suse 10). In Windows it is working fine(jdk 1.6_10 and jre 1.6_20). I have tried with different jdk,jre combinations ( jdk 1.6_25 etc )
I have resolved the problem using some trial and error.
Also I found, this is not os dependable as I have suspected earlier. This is easily reproducible and looks like an potential class loading bug.( though I am not sure whether it is in equinox implementation or in java !!).
Before explaining the solution, let me describe the scenario more elaborately.
We have our code deployed in a osgi(equinox) framework. There are two bundles which uses the c3p0 jar for database pooling and one of them exports the c3p0 packages. This bundle starts before the other one.
Now, according to osgi specification, osgi class loader should maintain separate class loader instances for separate bundles. Now when the second bundle tries to load classes from the c3p0 jar, its class-loader may find (from parent delegation) that the classes are already loaded !! But they are loaded from different context, which is causing the access violation.
This is initial findings, I will try to debug with the eclipse code and may be dig more into it. After changing the bundle start order, this is resolved.