@@ -45,6 +45,8 @@ This file is part of the iText (R) project.
45
45
import com .itextpdf .io .LogMessageConstant ;
46
46
import com .itextpdf .io .source .ByteArrayOutputStream ;
47
47
import com .itextpdf .io .source .ByteUtils ;
48
+ import com .itextpdf .io .util .FileUtil ;
49
+ import com .itextpdf .io .util .MessageFormatUtil ;
48
50
import com .itextpdf .kernel .PdfException ;
49
51
import com .itextpdf .kernel .utils .CompareTool ;
50
52
import com .itextpdf .test .ExtendedITextTest ;
@@ -59,8 +61,9 @@ This file is part of the iText (R) project.
59
61
import org .junit .experimental .categories .Category ;
60
62
import org .junit .rules .ExpectedException ;
61
63
64
+ import java .io .File ;
62
65
import java .io .IOException ;
63
- import com . itextpdf . io .util . MessageFormatUtil ;
66
+ import java . io .OutputStream ;
64
67
import java .util .ArrayList ;
65
68
import java .util .HashMap ;
66
69
import java .util .List ;
@@ -1638,6 +1641,24 @@ public void hugeInvalidIndRefObjNumberTest() throws IOException {
1638
1641
pdfDoc .close ();
1639
1642
}
1640
1643
1644
+ @ Test
1645
+ @ Ignore ("DEVSIX-2133" )
1646
+ public void testFileIsNotLockedOnException () throws IOException {
1647
+ File nonPdfFileName = new File (sourceFolder + "text_file.txt" );
1648
+ Assert .assertTrue (nonPdfFileName .exists ());
1649
+ boolean exceptionThrown = false ;
1650
+ try {
1651
+ PdfReader reader = new PdfReader (nonPdfFileName );
1652
+ } catch (com .itextpdf .io .IOException e ) {
1653
+ exceptionThrown = true ;
1654
+
1655
+ // File should be available for writing
1656
+ OutputStream stream = FileUtil .getFileOutputStream (nonPdfFileName );
1657
+ stream .write (new byte [] {0 });
1658
+ }
1659
+ Assert .assertTrue (exceptionThrown );
1660
+ }
1661
+
1641
1662
private boolean objectTypeEqualTo (PdfObject object , PdfName type ) {
1642
1663
PdfName objectType = ((PdfDictionary ) object ).getAsName (PdfName .Type );
1643
1664
return type .equals (objectType );
0 commit comments