java.lang.LinkageError: loader constraint violation: when resolving method "javax.imageio.metadata.IIOMetadata.getAsTree(Ljava/lang/String;)Lorg/w3c/dom/Node;"

Hi,
I’m running my app on Jboss server and when I try to save document in PDF I’m getting this error:

Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "javax.imageio.metadata.IIOMetadata.getAsTree(Ljava/lang/String;)Lorg/w3c/dom/Node;" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, asposewobfuscated/qx, and the class loader (instance of ) for resolved class, javax/imageio/metadata/IIOMetadata, have different Class objects for the type org/w3c/dom/Node used in the signature
at asposewobfuscated.qx.a(Unknown Source)
at asposewobfuscated.qw.l(Unknown Source)
at asposewobfuscated.qw.c(Unknown Source)
at asposewobfuscated.ur.(Unknown Source)
at asposewobfuscated.uf.a(Unknown Source)
at asposewobfuscated.uj.e(Unknown Source)
at asposewobfuscated.tp.a(Unknown Source)
at asposewobfuscated.uc.j(Unknown Source)
at asposewobfuscated.uh.a(Unknown Source)
at asposewobfuscated.ae.a(Unknown Source)
at asposewobfuscated.q.a(Unknown Source)
at asposewobfuscated.n.a(Unknown Source)
at asposewobfuscated.q.a(Unknown Source)
at asposewobfuscated.ad.a(Unknown Source)
at asposewobfuscated.uh.e(Unknown Source)
at com.aspose.words.aky.d(Unknown Source)
at com.aspose.words.qj.a(Unknown Source)
at com.aspose.words.Document.a(Unknown Source)
at com.aspose.words.Document.a(Unknown Source)
at com.aspose.words.Document.h(Unknown Source)
at com.aspose.words.Document.save(Unknown Source)

Do you have any solution for this problem?
What kind of libraries are you using for xml parsing? Are they included in Aspose jar?

Regards,
Jakub Mytnik

Hi Jakub ,

Thanks for your inquiry.

Most of our Java products depend upon the JAI package (Java Advanced Imaging)
from Sun in order to process images. By looking at the stack trace, it
seems your problem is somehow related to JAI. Please configure JAI
package on your side, you can find jai 1.1.3 and jai-imageio 1.1 in the
following links:

https://docs.aspose.com/words/java/system-requirements/#optional-dependencies

Hope this helps you. If you still face problem, please share following detail for testing. I will investigate the issue on my side and provide you more information.

What environment are you running on?

  • OS (Windows Version or Linux Version)
  • Architecture (32 / 64 bit)
  • Java version
  • Please attach your input Word document.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi,
thank you for reply. I’ve managed to solve the problem using workaround - saving document first to DOC format, open it again and save in PDF.
However, now I got the same error in different situation., when calling method insertImage from DocumentBuilder class. It occurs every time, doesn’t depend on document or image.
I’ve tried to cofigure JAI but it didn’t help.
I’m running application on JBoss Server with parent-last class loading policy. Changing to parent-first helps but I can’t do that because it affects the other modules of application.
It doesn’t depend on OS, architecture or java version.
Can you provide any fix or workaround for this problem?

Best regards,
Jakub Mytnik

Hi Jakub ,

Thanks for your inquiry. It is nice to hear from you that you have found the workaround of your issue.

*jmytnik:

However, now I got the same error in different situation., when calling method insertImage from DocumentBuilder class. It occurs every time, doesn’t depend on document or image.
Can you provide any fix or workaround for this problem?*

Regarding issue with DocumentBuilder.insertImage, I suggest you please try the following code example to insert the image. Hope this helps you.

Document doc = new Document();
Shape shape = new Shape(doc, ShapeType.IMAGE);
shape.getImageData().setImage(MyDir + "Aspose Logo.png");
shape.setWidth(100);
shape.setHeight(100);
Paragraph para = new Paragraph(doc);
para.appendChild(shape);
doc.getFirstSection().getBody().appendChild(para);
doc.save(MyDir + "Out.docx");

*jmytnik:

I’ve tried to cofigure JAI but it didn’t help.
I’m running application on JBoss Server with parent-last class loading policy. Changing to parent-first helps but I can’t do that because it affects the other modules of application.
It doesn’t depend on OS, architecture or java version.*

This issue seem to be related to JAI setting with JBoss server. Please share which version of JBoss Server you are using. I will setup JBoss Server at my side. As soon as everything is setup,
we will test the issue at our end and will post the results here for
your kind reference.

Hi,
thank you for reply.
I tried your code and I got same error while executing line:

image.getImageData().setImageBytes(barcodeImageBytes);

I’m using JBoss 5.1.0.GA version but probably it occurs on other versions as well.
To reproduce problem the most important setting is class loading strategy: parent-first=false.

Best regards,
Jakub Mytnik

Hi Jakub,

Thanks
for sharing the detail.

I have logged a new Task in our issue tracking system as WORDSJAVA-816 to investigate the shared issue. We will investigate your issue at our end and will post the results here for
your kind reference asap.

Thank you for your patience and understanding.

Hi Jakub,

It would be great if you please share
following detail for investigation purposes.

  • Please attach your input MS Word document.
  • Please

create a runnable Java application that demonstrates the code you used to generate
your output document

As soon as you get these pieces of information to us we’ll start our investigation into your issue.