On Fri, 9 Jan 2026 01:24:08 GMT, Alexander Matveev <[email protected]> wrote:

> Is it possible that `parse()` will change exception being thrown in case if 
> file does not exist?

I assume you mean 
[javax.xml.parsers.DocumentBuilder#parse(java.io.File)](https://docs.oracle.com/en/java/javase/25/docs/api/java.xml/javax/xml/parsers/DocumentBuilder.html#parse(java.io.File))

As we have figured out the default JDK implementation (Xerces XML parser) 
throws `java.io.FileNotFoundException` if a file doesn't exist and throws 
`org.xml.sax.SAXParseException` if the file is a directory. Another DOM XML 
parser (a different version of Xerces?) may behave differently.

The use of `javax.xml.parsers.DocumentBuilder#parse(java.io.InputStream)` 
eliminates differences in how XML parsers handle file system I/O errors. 
jpackage implementation code delegates filesystem I/O to `java.nio.file.Files`, 
XML parser deals with the byte stream in memory. We don't depend on how XML 
parser reports filesystem I/O errors because it reads data from memory, not 
from the filesystem. 

In the test code it doesn't matter how specific XML parser handles I/O errors, 
so we can use `javax.xml.parsers.DocumentBuilder#parse(java.io.File)`.

> If we depend on `java.nio.file.NoSuchFileException` vs 
> `java.io.FileNotFoundException`, then lets throw exception we need by 
> checking if file exist first.

We don't depend on `java.io.FileNotFoundException`. We depend on 
`java.nio.file.NoSuchFileException` that `Files.readAllBytes(Path)` may throw 
before any `DocumentBuilder#parse(...)` is called.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29007#discussion_r2674555049

Reply via email to