程式狂想筆記

一個攻城師奮鬥史

0%

itextpdf 使用 PdfReader 遇到檔案 lock 住問題

最近換個環境執行,結果發現檔案刪除會失敗。我還以為是MultipartFile.transferTo 遇到 FileNotFoundException 問題,後來發現不是,檔案被 lock 掉。

但沒找到相關錯誤,我都有做close動作。

我後來發現這個錯誤訊息。

1
2
3
4
5
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.itextpdf.text.io.ByteBufferRandomAccessSource$1 (file:/C:/Users/XXX/.m2/repository/com/itextpdf/itextpdf/5.5.13/itextpdf-5.5.13.jar) to method java.nio.DirectByteBuffer.cleaner()
WARNING: Please consider reporting this to the maintainers of com.itextpdf.text.io.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

照相關錯誤找到java - itext Java 11 : Illegal reflective access by com. itextpdf.io.source.ByteBufferRandomAccessSource$1 - Cache One

1
new PdfReader(new FileInputStream(inFilePath)

補上FileInputStream就可以跑了。三小
反正採到一個很奇怪的雷。

參考: