On Thu, 8 Jan 2026 20:16:17 GMT, Alexey Semenyuk <[email protected]> wrote:

>> src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java line 
>> 167:
>> 
>>> 165:         try {
>>> 166:             final Document doc = XmlUtils.initDocumentBuilder().parse(
>>> 167:                     new 
>>> ByteArrayInputStream(Files.readAllBytes(appImageFilePath)));
>> 
>> would `.parse(appImageFilePath.toFile())` also work?
>
> Yes, but `DocumentBuilder#parse(java.io.File)` will throw `SAXException` if 
> the file doesn't exist, while `Files#readAllBytes(Path)` throws 
> `IOException`. This change will break the corresponding unit test. I already 
> tried it.
> 
> I switched to using `DocumentBuilder#parse(java.io.File)` in the test code 
> because it doesn't matter what exceptions it throws.

The exception thrown will depend on the DocumentBuilder implementation, but the 
DocumentBuilder bundled with JDK 25 seems to throw a IOException when parsing a 
non existent java.io.File

Exception in thread "main" java.io.FileNotFoundException: .../nonexistent.xml 
(The system cannot find the file specified)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:185)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:139)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:109)
        at 
java.base/sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:86)
        at 
java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:183)
        at 
java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:665)
        at 
java.xml/com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:150)
        at 
java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:862)
        at 
java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:826)
        at 
java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:137)
        at 
java.xml/com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:248)
        at 
java.xml/com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:335)
        at 
java.xml/javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:206)

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

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

Reply via email to