Project

Profile

Help

Bug #2250

The output file cannot be deleted after executing an XSLT transformation

Added by Radu Pisoi almost 5 years ago. Updated over 3 years ago.

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

100%

Legacy ID:
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

History

#1 Updated by O'Neil Delpratt almost 5 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

#2 Updated by Radu Pisoi almost 5 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.

#3 Updated by O'Neil Delpratt almost 5 years ago

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

#4 Updated by Community Admin almost 5 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.

#5 Updated by O'Neil Delpratt over 4 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.

#6 Updated by O'Neil Delpratt over 4 years ago

  • Status changed from Resolved to Closed

#7 Updated by O'Neil Delpratt almost 4 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

#8 Updated by O'Neil Delpratt almost 4 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)

#9 Updated by O'Neil Delpratt almost 4 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)

#10 Updated by Michael Kay over 3 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

#11 Updated by Michael Kay over 3 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.

#12 Updated by O'Neil Delpratt over 3 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.

#13 Updated by O'Neil Delpratt over 3 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.

#14 Updated by O'Neil Delpratt over 3 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