Project

Profile

Help

Bug #2250

closed

The output file cannot be deleted after executing an XSLT transformation

Added by Radu Pisoi about 10 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Category:
JAXP Java API
Sprint/Milestone:
Start date:
2014-12-08
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
9.6, 9.7
Fix Committed on Branch:
9.6
Fixed in Maintenance Release:
Platforms:

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
Actions #1

Updated by O'Neil Delpratt about 10 years ago

  • 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

Actions #2

Updated by Radu Pisoi about 10 years ago

  • 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.

Actions #3

Updated by O'Neil Delpratt about 10 years ago

  • Status changed from Resolved to In Progress
  • Assignee set to O'Neil Delpratt
Actions #4

Updated by Community Admin about 10 years ago

  • 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.

Actions #5

Updated by O'Neil Delpratt almost 10 years ago

  • % 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.

Actions #6

Updated by O'Neil Delpratt almost 10 years ago

  • Status changed from Resolved to Closed
Actions #7

Updated by O'Neil Delpratt about 9 years ago

  • 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
Actions #8

Updated by O'Neil Delpratt about 9 years ago

  • 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)
Actions #9

Updated by O'Neil Delpratt about 9 years ago

  • 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)
Actions #10

Updated by Michael Kay almost 9 years ago

  • Status changed from Closed to In Progress
  • Applies to branch 9.7 added

This bug has resurfaced in 9.7. It appears that the fix was not applied to the 9.7 development branch.

See https://saxonica.plan.io/boards/2/topics/6253

Actions #11

Updated by Michael Kay almost 9 years ago

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.

Actions #12

Updated by O'Neil Delpratt over 8 years ago

  • 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.

Actions #13

Updated by O'Neil Delpratt over 8 years ago

  • 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.

Actions #14

Updated by O'Neil Delpratt over 8 years ago

  • 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