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

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?

Related

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

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

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");

WELD-001408 Unsatisfied dependencies for type [DataSource] with qualifiers

I have the following that is causing the subjected error message in APP-A
#Inject #CtcDB
private DataSource ds;
I'm using an identical pattern with APP-B which does not complain of this error.
When I hover over ds in Eclipse while holding down the ctrl key, I get the following context menu for APP-B
Open #Inject Bean Resource.ds
Open Declaration
Open Declared Type
but in the APP-A with the dependency error I only get
Open Declaration
Open Declared Type
// The Resources class is basically the same b/n both apps except the qualifier is #CommitmentDB for APP-B
public class Resources {
#Produces
#Resource(mappedName="java:jboss/datasources/myjndids")
#CtcDB
private DataSource ds;
// And my annotation
#Qualifier
#Retention(RUNTIME)
#Target({ METHOD, FIELD, PARAMETER, TYPE })
public #interface CtcDB{
}
I know CDI is active (I have a beans.xml in WEB-INF) because I have a POM dependency which contains some injectable beans. When hovering with the ctr key for those injections I get the expected context menu (in both apps)
OK I figured it out myself. In the Resources class I had the wrong import for DataSource
import javax.activation.DataSource; \\instead of
import javax.sql.DataSource;
I must have clicked on the wrong Eclipse Quickfix and imported the wrong package.

GWT and getClass().getPackage()

I'm getting this error at runtime when I try to use getClass.getPackage().getImplementationVersion(), in my FooterViewImpl class, to show my project's version number (from the pom.xml file) on the web page. I think the error is from the gwt java-to-javascript compiler.
[ERROR] [OnlineGlom] - Line 52: The method getPackage() is undefined for the type Class<capture#1-of ? extends FooterViewImpl>
java.lang.RuntimeException: Deferred binding failed for 'org.glom.web.client.ClientFactory' (did you forget to inherit a required module?)
Should I expect this to work?
No.
getPackage() is not emulated by GWT: https://developers.google.com/web-toolkit/doc/latest/RefJreEmulation. The motto of GWT is to do the maximum at compile-time rather than runtime.

GWT 2.4: "An internal compiler exception occurred" in project that uses Hibernate for Bean Validation

It's been about 5 hrs since I decided to use JSR 303 Bean Validation in my GWT project and I gotta say I can't even express (politely) how deeply unsatisfied I am with lame documentation on the subject on Google's website.
I really hope you guys can help me.
I followed this blog post to add client-side bean validation to my project. Unfortunately it worked only once and threw an exception in runtime saying that I need to add Hibernate Validation sources to class path. I fixed that and decided to remassage my dependencies a little too (biggest mistake of my life) but I couldn't make it work ever again.
I can't play with Validation sample from GWT SDK either because it's uncompilable because it has two implementations of class ServerValidator. Weird.
So to simplify my question I created dummy GWT application using project wizard of IntelliJ IDEA.
I added following elements to module xml:
<inherits name="org.hibernate.validator.HibernateValidator"/>
<replace-with class="com.mySampleApplication.client.ClientValidatorFactory">
<when-type-is class="javax.validation.ValidatorFactory"/>
</replace-with>
Created ClientValidatorFactory:
package com.mySampleApplication.client;
import com.google.gwt.core.client.GWT;
import com.google.gwt.validation.client.AbstractGwtValidatorFactory;
import com.google.gwt.validation.client.GwtValidation;
import com.google.gwt.validation.client.impl.AbstractGwtValidator;
import javax.validation.Validator;
import javax.validation.groups.Default;
public class ClientValidatorFactory extends AbstractGwtValidatorFactory
{
#GwtValidation(value = {Organization.class}, groups = {Default.class, ClientGroup.class})
public interface GwtValidator extends Validator
{
}
#Override
public AbstractGwtValidator createValidator()
{
return GWT.create(GwtValidator.class);
}
}
And in onModuleLoad() method I added this single line which causes compiler to blow up
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
And finally I used following jars which I copied from Validation sample of GWT SDK.
hibernate-validator-4.1.0.Final-sources.jar
hibernate-validator-4.1.0.Final.jar
log4j-1.2.16.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
validation-api-1.0.0.GA-sources.jar
validation-api-1.0.0.GA.jar
But when I compile my project it gives following meaningless error:
In detailed GWT compiler log I see this:
Loaded 2315 units from persistent store.
Found 2282 cached units. Used 2282 / 2282 units from cache.
Added 0 units to persistent cache.
Validating newly compiled units
Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/engine/ConstraintViolationImpl_CustomFieldSerializer.java'
Line 33: No source code is available for type org.hibernate.validator.engine.ConstraintViolationImpl<T>; did you forget to inherit a required module?
Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/engine/ValidationSupport.java'
Line 43: No source code is available for type org.hibernate.validator.engine.ConstraintViolationImpl<T>; did you forget to inherit a required module?
Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/constraints/impl/EmailValidator.java'
Line 25: No source code is available for type org.hibernate.validator.constraints.Email; did you forget to inherit a required module?
Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/constraints/impl/ScriptAssertValidator.java'
Line 26: No source code is available for type org.hibernate.validator.constraints.Email; did you forget to inherit a required module?
Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/constraints/impl/URLValidator.java'
Line 26: No source code is available for type org.hibernate.validator.constraints.URL; did you forget to inherit a required module?
Errors in 'jar:file:/C:/work/externals/gwt/gwt-user.jar!/org/hibernate/validator/super/org/hibernate/validator/engine/PathImpl.java'
Line 72: No source code is available for type org.hibernate.validator.engine.NodeImpl; did you forget to inherit a required module?
Why can't it find classses? I have hibernate-validator-4.1.0.Final-sources.jar in my classpath.
Any thoughts ?
I uploaded my project here if you guys want to play with it.
Case closed, guys. Error was caused by lack of hibernate validation sources in classpath because of bug in IntelliJ IDEA. Details are here.