Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8249095

tools/javac/launcher/SourceLauncherTest.java fails on Windows

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 11
    • Fix Version/s: 16
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • CPU:
      generic
    • OS:
      windows

      Description

      On Windows the test tools/javac/launcher/SourceLauncherTest.java fails.
      This is due to a perennial problem, and manifests when a file is created with a Windows reserved names, please see the following:
      https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN#file_and_directory_names

      The error is this:
      https://hg.openjdk.java.net/jdk/jdk/file/c1f532e5f910/test/langtools/tools/javac/launcher/SourceLauncherTest.java#l428

      Exception running test testNoSourceOnClassPath: java.nio.file.NoSuchFileException: testNoSourceOnClassPath\auxSrc\Aux.java
      java.nio.file.NoSuchFileException: testNoSourceOnClassPath\auxSrc\Aux.java
              at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
              at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
              at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
              at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:235)
              at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478)
              at java.base/java.nio.file.Files.newOutputStream(Files.java:219)
              at java.base/java.nio.file.Files.newBufferedWriter(Files.java:2919)
              at java.base/java.nio.file.Files.newBufferedWriter(Files.java:2962)
              at toolbox.ToolBox$JavaSource.write(ToolBox.java:636)
              at toolbox.ToolBox.writeJavaFiles(ToolBox.java:565)
              at SourceLauncherTest.testNoSourceOnClassPath(SourceLauncherTest.java:269)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:566)
              at toolbox.TestRunner.runTests(TestRunner.java:89)
              at SourceLauncherTest.main(SourceLauncherTest.java:63)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:566)
              at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
              at java.base/java.lang.Thread.run(Thread.java:834)

      Here is an example using java source launcher:

      $ cat Test.java
      import java.io.*;
      import java.nio.file.*;
      public class Test {
          public static void main(String... args) throws Exception {
      if (args == null || args.length < 1) {
                  throw new Error("Usage: need one pathspec argument");
      }
              Path file = Path.of(args[0]);
      Files.createDirectories(file.getParent());
      try (BufferedWriter out = Files.newBufferedWriter(file)) {
                  out.write("An auk or alcid is a bird of the family of Alcidae.");
      }
          }
      }

      $ BLAH/images/jdk/bin/java Test.java foo/Aux.java
      Exception in thread "main" java.nio.file.NoSuchFileException: foo\Aux.java
              at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
              at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
              at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
              at java.base/sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:235)
              at java.base/java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:478)
              at java.base/java.nio.file.Files.newOutputStream(Files.java:219)
              at java.base/java.nio.file.Files.newBufferedWriter(Files.java:2919)
              at java.base/java.nio.file.Files.newBufferedWriter(Files.java:2962)
              at Test.main(Test.java:16)

      $ BLAH/images/jdk/bin/java Test.java foo/Auk.java
      $ cat foo/Auk.java
      An auk or alcid is a bird of the family of Alcidae.


      So changing the name from Aux.java or class Aux to Auk will work for the test. I am not sure why javac did not catch this please see JDK-6241975.

      I discovered this with jdk11.0.8 and why hasn't anyone else encountered this issue ?

      My suggestion is to enhance toolbox and other test helpers to check for these reserved keywords and warn the developer up front.

      Running on Windows Server 2016.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jjg Jonathan Gibbons
                Reporter:
                ksrini Kumar Srinivasan
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: