8

On Windows, NUL is the null output device similar to /dev/null on Linux.

With Oracle Java 8 Update 331, trying to get a new FileOutputStream("NUL:") throws an exception. Previously (Java 8u321) it worked fine.

The problem seems to be the colon:

  • new FileOutputStream("NUL") - OK
  • new FileOutputStream("NUL:") - exception

Can anyone point me to docs or JDK sources regarding this change? I can't change the code itself because it is in a 3rd party lib (xnio-api).

try
{
  new FileOutputStream("NUL:");
  System.out.println("OK");
}
catch (FileNotFoundException e)
{
  System.out.println(e);
}
nodots
  • 1,450
  • 11
  • 19
  • Just for reference: https://stackoverflow.com/questions/313111/is-there-a-dev-null-on-windows – GhostCat Apr 22 '22 at 09:00
  • Relevant entry in Oracle Bug Database: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8285445 – nodots Apr 29 '22 at 11:32
  • 3
    Fixed in Oracle Java **8u333** – nodots May 05 '22 at 07:00
  • 2
    And for completeness, it's also fixed in the library; `NUL:` has been replaced by `NUL` in [xnio-api 3.8.7.Final](https://mvnrepository.com/artifact/org.jboss.xnio/xnio-api/3.8.7.Final) via ticket [XNIO-404](https://github.com/xnio/xnio/commit/4e2db8d397e5798a8ca27315dad3e12e9927e45b) – slindenau May 19 '22 at 07:37

1 Answers1

13

I suspect this is the offending change.

Apparently it tries to avoid accessing ADS (alternate data streams), but seems to "accidentally" also prevent access to device-files like this.

If that's correct, then you can try setting the system property jdk.io.File.enableADS to true to re-enable the old behaviour.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
  • Thank you, it works. Now I need to evaluate the implications of having ADS enabled... :) – nodots Apr 22 '22 at 09:19
  • 3
    Maybe it helps. I used the workaround in my wildfly environment, but was not working. E.g: I started wildfly like "standalone.bat -Djdk.io.File.enableADS=true --server-config=my.xml" But I found, the system property was for the application and not for the JVM. Adding the system property to standalone.conf.bat like: set "JAVA_OPTS=%JAVA_OPTS% -Djdk.io.File.enableADS=true" This was passed to the JVM. Standalone.conf looks is passed to the application level (based on order) (I'm not a wildfly expert, maybe the are more elegant ways.) – ula.uvula Apr 26 '22 at 10:22
  • -Djdk.io.File.enableADS=true works for me ,jdk11 on windows11 , thank you – twocold Jul 26 '22 at 03:41