Maven does not correctly resolve Windows mapped network drives with Java 25
Affected version
3.9.11
Bug description
I have an H: drive mapped in Windows to a network path \\colo-01-fs02\developers$\ollie. Required by my workplace.
I can build my projects just fine in Java 21 and below.
When I build with OpenJDK 25 - literally no difference except to repoint JAVA_HOME - then Maven incorrectly expands the network location and suffixes it onto the drive:
H:\work\html-uis\konsolidator>mvn compile -X
Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)
Maven home: C:\Programs\apache-maven-3.9.11
Java version: 25, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-25
Default locale: en_GB, platform encoding: UTF-8
OS name: "windows server 2022", version: "10.0", arch: "amd64", family: "windows"
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner (file:/C:/Programs/apache-maven-3.9.11/lib/guice-5.1.0-classes.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.inject.internal.aop.HiddenClassDefiner
WARNING: sun.misc.Unsafe::staticFieldBase will be removed in a future release
[DEBUG] Reading global settings from C:\Programs\apache-maven-3.9.11\conf\settings.xml
...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-readable POM H:\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\pom.xml: H:\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\pom.xml (The system cannot find the path specified) @ H:\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\pom.xml
The correct path here should of course either be H:\work\... or the network path \\colo-01-fs02\....
Based on the release notes of JDK 25 https://jdk.java.net/25/release-notes there had been several changes related to file/path handling in the JDK... Can you check with JDK 24 and maybe even before...
@ollierob can you provide a stack trace for it?
Error stack from running with -e:
[ERROR] The project com.atm.apps.http:konsolidator-protos:1.0-SNAPSHOT (\\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\protos\pom.xml) has 1 error
[ERROR] Non-readable POM H:\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\pom.xml: H:\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\pom.xml (The system cannot find the path specified) @ H:\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\pom.xml
java.io.FileNotFoundException: H:\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\pom.xml (The system cannot find the path specified)
at java.io.FileInputStream.open0 (Native Method)
at java.io.FileInputStream.open (FileInputStream.java:185)
at java.io.FileInputStream.<init> (FileInputStream.java:139)
at org.apache.maven.building.FileSource.getInputStream (FileSource.java:46)
at org.apache.maven.model.building.DefaultModelBuilder.readModel (DefaultModelBuilder.java:552)
at org.apache.maven.model.building.DefaultModelBuilder.readParentLocally (DefaultModelBuilder.java:863)
at org.apache.maven.model.building.DefaultModelBuilder.readParent (DefaultModelBuilder.java:798)
at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:327)
at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:243)
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:447)
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:410)
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:546)
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:410)
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:367)
at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:349)
at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:340)
at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:76)
at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:448)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:197)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
at java.lang.reflect.Method.invoke (Method.java:565)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Run mvnDebug with 3.9.x branch checked out. The issue seems to be with FileModelSource.getRelatedSource where this part becomes malformed:
new File(relatedPom.toURI().normalize())
with inputs
relPath => "..\pom.xml"
getFile() => \\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\protos\pom.xml
relatedPom => \\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\protos\..\pom.xml
relatedPom.toURI() =>file:////colo-01-fs02/developers$/ollie/work/html-uis/konsolidator/protos/../pom.xml
relatedPom.toURI().normalize() => file:/colo-01-fs02/developers$/ollie/work/html-uis/konsolidator/pom.xml
Would it be safe to say this is a JDK 25 URI normalization bug?
Also worth noting an apparent difference in file canonicalization which is generating the network path in the first place in DefaultProjectBuilder.build:
#Oracle OpenJDK 21
moduleFile => H:\work\html-uis\konsolidator\protos\pom.xml
moduleFile.getCanonicalFile() => H:\work\html-uis\konsolidator\protos\pom.xml
#Oracle OpenJDK 25
moduleFile => H:\work\html-uis\konsolidator\protos\pom.xml
moduleFile.getCanonicalFile() => \\colo-01-fs02\developers$\ollie\work\html-uis\konsolidator\protos\pom.xml
Apparently this is due to https://bugs.openjdk.org/browse/JDK-8355342
Note the comments here which talk about using Path.toRealPath instead of canonicalization - is there an argument that Maven should follow this advice? FWIW,
#Oracle OpenJDK 25
moduleFile.toPath().toRealPath() => H:\work\html-uis\konsolidator\protos\pom.xml
FWIW, Maven 4 should not be affected by the problem, as the switch to the NIO2/Path API has removed most calls to getCanonicalFile(). I don't have any Windows VM available at hand. @ollierob could you double check if using Maven 4.0.0-rc-4 works better ?
I can try Maven 4, but if this works will it be back-portable or is there going to be a decision that only Maven 4 fully supports Java 24+?
I think the use of getCanonicalFile and toRealPath should both be removed from the code base. There's no good reason why Maven should use those when dealing with projects. I think they can now safely be replaced with path.toAbsolutePath().normalize().
See https://github.com/apache/maven/commit/92d53cb7075d4ff62fff0a05c7bc6b1d51566db8