On Thu, 8 Jan 2026 20:52:12 GMT, Johannes Döbler <[email protected]> wrote:
>> 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) Sorry, my comment was incorrect: SAXException is thrown when the directory is passed into `DocumentBuilder#parse(java.io.File)`: org.xml.sax.SAXParseException; systemId: file:/C:/AppData/Local/Temp/junit10902338938727647559/.jpackage.xml/; lineNumber: 1; columnNumber: 1; Premature end of file. Whet it is passed to `Files#readAllBytes(Path)` it throws IOException: java.nio.file.AccessDeniedException: C:\AppData\Local\Temp\junit17123875824397995430.jpackage.xml This change causes failure of the AppImageFileTest#testDirectory test case at https://github.com/openjdk/jdk/blob/385c4f8180d30c0e41b848eb4b2c1c8788211422/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/AppImageFileTest.java#L118: org.opentest4j.AssertionFailedError: expected: <Failed to read ".jpackage.xml" file in the predefined app image "C:\AppData\Local\Temp\junit10902338938727647559"> but was: <".jpackage.xml" file in the predefined app image "C:\AppData\Local\Temp\junit10902338938727647559" contains malformed XML data> at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132) at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197) at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182) at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177) at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1141) at jdk.jpackage/jdk.jpackage.internal.AppImageFileTest.testDirectory(AppImageFileTest.java:122) at [email protected]/java.lang.reflect.Method.invoke(Method.java:580) at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1597) at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1597) AppImageFileTest#testNoSuchFile test case at https://github.com/openjdk/jdk/blob/385c4f8180d30c0e41b848eb4b2c1c8788211422/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/AppImageFileTest.java#L111 also fails because of an unexpected exception type. In case of a non-existant file, `DocumentBuilder#parse(java.io.File)` throws `java.io.FileNotFoundException`, and `Files#readAllBytes(Path)` throws `java.nio.file.NoSuchFileException`. This change fails AppImageFileTest#testNoSuchFile test case: org.opentest4j.AssertionFailedError: expected: <".jpackage.xml" file is missing in the predefined app image "C:\AppData\Local\Temp\junit3266296985241385507"> but was: <Failed to read ".jpackage.xml" file in the predefined app image "C:\AppData\Local\Temp\junit3266296985241385507"> at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151) at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132) at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197) at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182) at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177) at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1141) at jdk.jpackage/jdk.jpackage.internal.AppImageFileTest.testNoSuchFile(AppImageFileTest.java:113) at [email protected]/java.lang.reflect.Method.invoke(Method.java:580) at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1597) at [email protected]/java.util.ArrayList.forEach(ArrayList.java:1597) ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29007#discussion_r2674044610
