Itext Java 11: Illegal reflective access by com.itextpdf.io.source.ByteBufferRandomAccessSource$1

D. Millard :

Recently upgraded to Java 11 and began performing a regression check. Currently get an Illegal reflective access error when trying to call com.itextpdf.text.pdf.PdfReader.close. Currently on Itext version 5.5.13 but also tried on itext 7.0.0 and had same issue.

Does anyone have any suggestions on how to fix compatibility issues between Java-11 and Itext?

WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by com.itextpdf.io.source.ByteBufferRandomAccessSource$1 (file:...repository/com/itextpdf/io/7.0.0/io-7.0.0.jar) to method java.nio.DirectByteBuffer.cleaner() WARNING: Please consider reporting this to the maintainers of com.itextpdf.io.source.ByteBufferRandomAccessSource$1 WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release

Alexey Subach :

While I second the comments encouraging you to debug the code and find the root cause (and then submit a pull request), or creating an issue in iText Jira if you are a customer with a support contract (which would raise the priority of the issue), here is a workaround suggestion (that I haven't tested, but I chances are it will work):

Use PdfReader and PdfWriter constructors that accept InputStream and OutputStream, respectively. In this case the code causing the problem should not be invoked. Same thing for all the other cases in which iText interacts with your file system - wrap everything into InputStream/OutputStream, or deal with byte[] arrays.

So this line:

new PdfDocument(new PdfReader(inFilePath), new PdfWriter(outFilePath))

becomes this one:

new PdfDocument(new PdfReader(new FileInputStream(inFilePath)), 
                new PdfWriter(new FileOutputStream(outFilePath)))

You might also want to wrap the streams into BufferedInputStream/BufferedOutputStream.

Similarly, when dealing with PdfFontFactory, use methods that accept byte[] instead of String representing file path and so on.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=76934&siteId=1