JDK-8285499 : new FileOutputStream("NUL:") shows "Invalid path or file name"
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 8u331
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2022-04-22
  • Updated: 2022-04-23
  • Resolved: 2022-04-23
Related Reports
Duplicate :  
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
Windows 7 / 10 / JRE 8u331

A DESCRIPTION OF THE PROBLEM :
After updating JRE 8 version version 202, to 331, new FileOutputStream("NUL:") shows "Invalid path or file name".

Original Method:

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);
      }
    }
  });

REGRESSION : Last worked in version 8

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
try {
  new FileOutputStream("NUL:").getChannel();
} catch (FileNotFoundException e) {
  e.printStackTrace();
}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
new FileOutputStream, to call method "getChannel()"
ACTUAL -
FileNotFoundException 

FREQUENCY : always



Comments
This issue looks like a duplicate of JDK-8285445.
23-04-2022