RFR: 8268222: javax/xml/jaxp/unittest/transform/Bug6216226Test.java failed, cannot delete file

Daniel Fuchs dfuchs at openjdk.java.net
Fri Jun 4 08:54:59 UTC 2021


On Fri, 4 Jun 2021 05:14:13 GMT, Joe Wang <joehw at openjdk.org> wrote:

> Revert changes in StreamResult.java made through https://github.com/openjdk/jdk/pull/4318 since it was creating a file stream on behalf of the Transformer, which resulted in a leaking file handle because the Transformer would only close files it opened.
> 
> This change instead replace the problematic file-uri-url-file conversion code with nio Paths. While we generally don't make such changes if it's not necessary as Apache still supports older versions of the JDK, we are okay with a code level 8.

Using `Path` instead of trying to handcraft a URL is a much better alternative.

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java line 52:

> 50: import java.net.UnknownServiceException;
> 51: import java.nio.file.Path;
> 52: import java.nio.file.Paths;

Nit: you should not need to use Paths. `Paths.get(URI)` just calls `Path.of(URI)`

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java line 516:

> 514:                 if (systemId.startsWith("file:")) {
> 515:                     try{
> 516:                         Path p = Paths.get(new URI(systemId));

I suggest using `Path.of(new URI(systemId));` here.

-------------

Marked as reviewed by dfuchs (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/4353


More information about the core-libs-dev mailing list