It seems you're running into this problem: Java: FileOutputStream("NUL:") not working after Java upgrade
The code you're referencing that is causing the problem is from https://code.yawk.at/org.jboss.xnio/xnio-api/3.8.4.Final/org/xnio/conduits/Conduits.java
static {
NULL_FILE_CHANNEL = AccessController.doPrivileged(new PrivilegedAction<FileChannel>() {
public FileChannel run() {
final String osName = System.getProperty("os.name", "unknown").toLowerCase(Locale.US);
try {
if (osName.contains("windows")) {
return new FileOutputStream("NUL:").getChannel();
} else {
return new FileOutputStream("/dev/null").getChannel();
}
} catch (FileNotFoundException e) {
throw new IOError(e);
}
}
});
}
I've looked at the sources for this release (3.8.4
) and the most recent release on maven central (3.8.7
): https://mvnrepository.com/artifact/org.jboss.xnio/xnio-api/3.8.7.Final
And there is some good news, it has been fixed in the latest release of xnio-api
. The current code in version 3.8.7
is now as follows: (NUL:
was replaced by NUL
)
if (osName.contains("windows")) {
return new FileOutputStream("NUL").getChannel();
} else {
return new FileOutputStream("/dev/null").getChannel();
}
So if it's possible i would suggest you try to upgrade your dependency so that xnio-api-3.8.7.Final.jar
is used.
Update 09-2022
Thanks to the comment of @NicolasRiousset, who found the following issue logged on jhipster's github, i have further traced this problematic dependency.
It starts with the optional
dependency to spring-boot-starter-undertow
, which in turn depends on undertow-core
, and that depends on xnio-api
from Jboss.
The earliest version that includes the fix (xnio-api-3.8.7
) can be found in undertow-core 2.2.18.Final
. The earliest version that uses this is spring-boot-starter-undertow 2.7.1
.
And JHipster starts including spring-boot
version >= 2.7.1
from jhipster-framework 7.9.0
.
So upgrading to JHipster >= 7.9.0
should fix this problematic xnio-api
dependency.
In case you don't strictly need undertow
as your embedded web server, you can also switch (back) to spring-boot-starter-tomcat
, since tomcat doesn't use the xnio-api
.
Otherwise the mentioned system property should indeed also be a valid workaround for now. Since the code is statically loaded, i think you'll have to use VM arguments to include it in your program instead of using System.setProperty
.
So add -Djdk.io.File.enableADS=true
to your programs startup/command line.
See for reference the following question that was mentioned in the comments: How to set system property?
It does also seem to be fixed in newer version of the Java runtime, so upgrading your JDK/JRE is also an option. According to the linked question at the top it's fixed in Java 8u333, and on my test system with Java 17.0.2 both versions of NUL
also work.