Bug #2250
closed
The output file cannot be deleted after executing an XSLT transformation
Applies to branch:
9.6, 9.7
Fix Committed on Branch:
9.6
Fixed in Maintenance Release:
Description
After I executed an XSLT transformation from a Java program the output file seems to be locked because it cannot be deleted.
The usual reason why this problem happens, is that the output stream over the file is not closed.
I can reproduce this issue from the next simple Java program with Saxon 9.6.0.3:
public static void main(String[] args) throws TransformerException, InterruptedException {
// Create transformer
File xslFile = new File(xslPath);
InputSource inputSource = new InputSource(xslFile.toURI().toString());
Source source = new SAXSource(inputSource);
TransformerFactory transformerFactory = new ProfessionalTransformerFactory();
Transformer transformer = transformerFactory.newTransformer(source);
// Create XML SAX source
Source xmlSource = new SAXSource(new InputSource(new File(xmlPath)
.toURI().toString()));
// Output stream result
File outFile = new File(outPath);
Result outputTarget = new StreamResult(outFile);
// Run transformation
System.out.println("Run transformation...");
transformer.transform(xmlSource, outputTarget);
System.out.println("Output file exists: " + outFile.exists());
System.out.println("Can the output file be deleted? " + outFile.delete());
}
In my case, the result of the transformation is:
Run transformation...
Output file exists: true
Can the output file be deleted? false
- Category set to JAXP Java API
- Status changed from New to Resolved
- Assignee set to O'Neil Delpratt
- Priority changed from Low to Normal
- % Done changed from 0 to 100
- Found in version set to 9.6
Thanks for reporting the problem you have found. We managed to reproduce and fix the bug. The problem was caused due to changes in Saxon 9.6 where we now implement the JAXP interface via the Saxon s9api interface.
The fix applied in the TransformerImpl class. The patch will be available in the next maintenance release
- Assignee deleted (
O'Neil Delpratt)
- % Done changed from 100 to 0
I've copied the patch on our side to fix the problem until a new Saxon version will be released.
Unfortunately, the fix doesn't work for me due to the output file is still locked and it cannot be deleted.
I've tested with the Java sample from the issue description.
- Status changed from Resolved to In Progress
- Assignee set to O'Neil Delpratt
- Status changed from In Progress to Resolved
The proposed fix seems to work now and is committed to the Saxon 9.6 subversion branch:
Fix applied in the transform method of the TransformerImpl class. Specially, in the path where we are writing to a file we now pass the File object directly to the Serializer, which in turn switches on the mustClose boolean flag in the Serializer class. Therefore the destination close method does as we expect when it is called.
I have added the test case testOutFileClosed() in the Serializer junit tests for the JAXP interface to check for regression in future releases. It should also be noted that we need to run this junit test on different platforms to make sure we get the desired outcome on all of them.
- % Done changed from 0 to 100
- Fixed in version set to 9.6.0.4
Bug fix applied in the Saxon 9.6.0.4 maintenance release.
- Status changed from Resolved to Closed
- Sprint/Milestone set to 9.6.0.4
- Applies to branch 9.6 added
- Fix Committed on Branch 9.6 added
- Fixed in Maintenance Release 9.6.0.4 added
- Sprint/Milestone changed from 9.6.0.4 to 9.6.0.3
- Fixed in Maintenance Release 9.6.0.3 added
- Fixed in Maintenance Release deleted (
9.6.0.4)
- Sprint/Milestone changed from 9.6.0.3 to 9.6.0.4
- Fixed in Maintenance Release 9.6.0.4 added
- Fixed in Maintenance Release deleted (
9.6.0.3)
- Status changed from Closed to In Progress
- Applies to branch 9.7 added
Note: the unit test that was written to check for this problem was run on 9.7, but not, unfortunately, on Windows. On other platforms it is much harder to check whether a file/stream has been closed.
- Status changed from In Progress to Resolved
- Found in version deleted (
9.6)
- Fixed in version deleted (
9.6.0.4)
We have applied a fix to this in the Serializer class to close the file on completion.
Regression testing done, but not tested on all platforms.
- Status changed from Resolved to Closed
- Fixed in Maintenance Release 9.6.0.9 added
- Fixed in Maintenance Release deleted (
9.6.0.4)
Bug fix applied in the Saxon 9.6.0.9 maintenance release.
- Fixed in Maintenance Release 9.6.0.4 added
- Fixed in Maintenance Release deleted (
9.6.0.9)
Please register to edit this issue
Also available in: Atom
PDF