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

StringIndexOutOfBoundsException in Path.getFileName() with symlink

XMLWordPrintable

    • x86_64
    • windows

      ADDITIONAL SYSTEM INFORMATION :
      Reproducible at least on JDK11 and JDK15.

      A DESCRIPTION OF THE PROBLEM :
      Path.getFileName() throws StringIndexOutOfBoundsException when the path is a symlink to a network share.

      I understand that the problem is in 'WindowsPathParser.parse()', which always appends trailing '\\' to '\\server\share', resulting in 'root' variable being longer than 'path'.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Create a symlink to amn existing network share with:
          mklink /d C:\temp\link \\localhost\share
      2) Use test snippet

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Path.getFileName() shall return null
      ACTUAL -
      Path.getFileName() throws StringIndexOutOfBoundsException

      ---------- BEGIN SOURCE ----------
      final Path path = Paths.get("C:/temp/link");
      final Path realPath = path.toRealPath();
      final Path fileName = realPath.getFileName();
      ---------- END SOURCE ----------

      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: