JDK-8051853 : new URI("x/").resolve("..").getSchemeSpecificPart() returns null!
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7,8
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2012-09-13
  • Updated: 2020-09-09
  • Resolved: 2019-11-25
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 8 Other
8u251 b01Fixed openjdk8u282Fixed
Description
FULL PRODUCT VERSION :
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) Client VM (build 23.3-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6002]

A DESCRIPTION OF THE PROBLEM :
new URI("x/").resolve("..").getSchemeSpecificPart() returns null!

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code above.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
new URI("x/").resolve("..").getSchemeSpecificPart() should return an empty string.
ACTUAL -
new URI("x/").resolve("..").getSchemeSpecificPart() returns null!

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.URI;

public class Test {
    public static void main(String[] args) {
        System.out.println(new URI("x/").resolve("..").getSchemeSpecificPart() );
    }
}
---------- END SOURCE ----------

Comments
Fix Request (8u): Push to 8u requested because this issue was fixed in 8u251-oracle. Patch was prepared only for 8u because the problem is not reproducible with 9+. Review thread link is added to the "Issue Links" section above.
07-09-2020

It seems this was fixed as part of JDK-8146686 in OpenJDK 9+. The culprit is the rather odd special casing of a zero length buffer, which would happily be turned into the empty string by StringBuffer.toString(), but instead the method returns early and schemeSpecificPart is left unset. https://hg.openjdk.java.net/jdk-updates/jdk9u/jdk/rev/16296b4145d005e#l1.30 Thanks to Alex Kashchenko for finding this.
07-09-2020

I can observe the issue on jdk1.7.0_71, jdk1.8.0_211, but 9, 10, 11, 12, 13 and mainline behave properly.
11-10-2019

This seems to be fixed in jdk-dev. I haven't checked since when - but 12 doesn't have the issue.
15-11-2018