JDK-8037945 : Paths.get("").normalize() throws ArrayIndexOutOfBoundsException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7u51
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-03-19
  • Updated: 2015-01-06
  • Resolved: 2014-03-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u76Fixed 8u20Fixed 9 b08Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
All of JDK 8, JDK7 u51 and OpenJDK 7u51 have the problem

ADDITIONAL OS VERSION INFORMATION :
Ubuntu Linux 13.10, x86-64

A DESCRIPTION OF THE PROBLEM :
fge@alustriel:/tmp$ cat Foo.java 
import java.nio.file.Paths;


public class Foo
{
    public static void main(final String... args)
    {
        System.out.printf("'%s'\n", Paths.get("").normalize());
        System.exit(0);
    }
}
fge@alustriel:/tmp$ javac Foo.java 
fge@alustriel:/tmp$ java Foo
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
	at sun.nio.fs.UnixPath.normalize(UnixPath.java:508)
	at Foo.main(Foo.java:8)


REGRESSION.  Last worked in version 6u45

ADDITIONAL REGRESSION INFORMATION: 
Does NOT happen on Windows systems. I don't have other Unix systems than Linux to test on.

I only discovered the bug recently... I set the "prior working release" to the latest JDK 6 version since it didn't have Path...

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See description...

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Return an empty path
ACTUAL -
See description...

ERROR MESSAGES/STACK TRACES THAT OCCUR :
See description...

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.nio.file.Paths;


public class Foo
{
    public static void main(final String... args)
    {
        System.out.printf("'%s'\n", Paths.get("").normalize());
        System.exit(0);
    }
}

---------- END SOURCE ----------


Comments
The normalize method doesn't handle the empty path case, easy fix.
20-03-2014