XliffReader.close() do not close the documents in a Exception case
Issue #35
new
The XliffReader do not closes the resource in case of an Exception.
This results in a FileSystemException if you try to delete the file after that (I know it’s very rare case)
java.nio.file.FileSystemException: Some xliff file: The process cannot access the file because it is being used by another process.
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:269)
at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
at java.nio.file.Files.delete(Files.java:1126)
at ch.aeis.importer.MainImport.main(MainImport.java:88)
Example Code:
try(XLIFFReader reader = new XLIFFReader(XLIFFReader.VALIDATION_MAXIMAL)) {
reader.open(Paths.get("Some File Path").toFile());
if (true) {
throw new RuntimeException("Some strange Exception");
}
} catch (Exception e) {
System.out.println("Exception gefunden - " + e);
}
try {
Files.delete(Paths.get("Some File Path"));
System.out.println("Success");
} catch (IOException e) {
System.out.println("Something went wrong!");
}