iText / BouncyCastle throws “java.lang.VerifyError: class overrides final method equals”

牧云@^-^@ 提交于 2019-11-27 03:22:14

问题


We have an application that creates PDFs unsing jasperreports.
It also manipulates said PDFs using iText after they have been created.

We recently started using encryption on some PDF. That means before the app can handle the PDF after its creation, it has to be decrypted. While attempting to do so using iText's PdfReader(String path, byte[] password) I get the following exception:

java.lang.VerifyError: class org.bouncycastle.asn1.ASN1Primitive overrides final method equals.(Ljava/lang/Object;)Z
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at com.simontuffs.onejar.JarClassLoader.defineClass(JarClassLoader.java:561)
    at com.simontuffs.onejar.JarClassLoader.findClass(JarClassLoader.java:475)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.itextpdf.text.pdf.PdfEncryption.<init>(PdfEncryption.java:148)
    at com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj(PdfReader.java:914)
    at com.itextpdf.text.pdf.PdfReader.readDocObj(PdfReader.java:1294)
    at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:643)
    at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:187)
    at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:212)
    at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:202)

The project is built as a runnable .jar using Maven and uses the following dependencies:
iText 5.4.2
bouncycastle 1.48

I should mention that jasperreports has its own dependency of iText and bouncycastle:
iText 2.1.7
bouncycastle 1.38

I can't figure out what's going on on and need help.


回答1:


My best guess is that you have ended up with two different versions of Bouncy Castle on your classpath, and it happened so that the classloader has loaded the superclass from one version and is now trying to load the subclass from the other. The versions are different in that one of them defines a final equals method.




回答2:


Had same error, my solution might come in handy. In my case all i was doing was digital signature of pdf documents, using Maven i had both IText(itextpdf.jar/version 5.4.2) & Bouncycastle(bcprov-jdk15on.jar/version 1.55) dependency in my pom.xml. Then i read a part in this iText book Digital Signatures for PDF documents about Bouncycastle-related problems.I removed the Bouncycastle(bcprov-jdk15on.jar/version 1.55) dependency and the error was gone(noob mistake- the bouncycastle dependency was already part of the itext dependency no need to have the two seperately).

NOTE: if you run into any Bouncycastle class file not found errors after removing bouncycastle dependency check this




回答3:


I had similiar problem because I had two different artifacts on my classpath:

<groupId>org.bouncycastle</groupId>
<artifactId>bcprov</artifactId>

and

 <groupId>org.bouncycastle</groupId>
 <artifactId>bcprov-jdk15on</artifactId>

I have excluded the bcprov, which solved the issue for me.



来源:https://stackoverflow.com/questions/17212410/itext-bouncycastle-throws-java-lang-verifyerror-class-overrides-final-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!