The latest version of Aspose.Words for Java (21.5) breaks when the aspose-words.jar is used as an embedded dependency inside of another JAR file.
We are shipping our application as an OSGI bundle where are non-OSGI dependencies are embedded inside of our bundles JAR file (nested JAR files):
.
├── scroll-words.jar
│ ├── META-INF
│ │ ├── MANIFEST.MF
│ │ ├── lib
│ │ │ ├── aopalliance-repackaged-2.6.1.jar
│ │ │ ├── aspose-words-21.3-jdk17.jar
│ │ │ ├── commons-collections4-4.4.jar
│ │ │ ├── commons-compress-1.20.jar
…
This is the shortened stack trace we are seeing when we call new com.aspose.words.Document(…) in our code:
java.lang.ExceptionInInitializerError
at com.aspose.words.zzZ85.zzZ(Unknown Source)
at com.aspose.words.zzZ85.zzXg(Unknown Source)
at com.aspose.words.zzZ81.zzXE(Unknown Source)
at com.aspose.words.Document.zzY(Unknown Source)
at com.aspose.words.Document.zzZ(Unknown Source)
at com.aspose.words.Document.<init>(Unknown Source)
at com.aspose.words.Document.<init>(Unknown Source)
at com.aspose.words.Document.<init>(Unknown Source)
at com.k15t.scroll.words.exporter.WordsExporter.parseDocument(WordsExporter.java:287)
[... unrelated calls ... ]
Caused by: java.lang.IllegalArgumentException: bytes cannot be null
at com.aspose.words.internal.zz1B.zzZp(Unknown Source)
at com.aspose.words.zzZ87.<init>(Unknown Source)
at com.aspose.words.zzZ87.<clinit>(Unknown Source)
... 59 more
We have tracked this down to the introduction of a new check in 21.5 that likely is supposed to check if the aspose-words.jar is still signed:
if (this.getClass().getProtectionDomain().getCodeSource().getCertificates() == null) {
throw new IllegalStateException();
}
When the jar is nested in a different jar this however checks if the outer jar is signed instead (our jar, which is not signed). The thrown exception is then caught and supposed to be rethrown with another message which is not initialized yet due to it happening in the static initialization, which in turn causes this “bytes cannot be null” message.
Due to this we are blocked from upgrading to 21.5. This sort of bundling of dependencies is not unusual. As far as I remember spring-boot also works in a similar way, so I would not be surprised if other users will run into this at some point as well.