FULL PRODUCT VERSION : java version "1.8.0_25" Java(TM) SE Runtime Environment (build 1.8.0_25-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode) ADDITIONAL OS VERSION INFORMATION : Darwin leitang-MacBook-Pro.local 14.5.0 Darwin Kernel Version 14.5.0: Sun Sep 25 22:07:15 PDT 2016; root:xnu-2782.50.9~1/RELEASE_X86_64 x86_64 A DESCRIPTION OF THE PROBLEM : public static void main(String[] args) { try { String xx = "http://coder_1.tanglei.name"; java.net.URI u = new java.net.URI(xx); System.out.println(u); System.out.println(u.getHost()); // null java.net.URL url = new java.net.URL(xx); System.out.println(url); System.out.println(url.getHost()); // coder_1.tanglei.name java.net.URI u2 = new java.net.URI(url.getProtocol(), url.getHost(), url.getPath(), ""); System.out.println(u2); } catch (Exception e){ System.out.println("exception got: " + e.getMessage()); } } "_" is not allowed in java.net.URI but is allowed in java.net.URL. output: http://coder_1.tanglei.name null http://coder_1.tanglei.name coder_1.tanglei.name exception got: Illegal character in hostname at index 12: http://coder_1.tanglei.name# REGRESSION. Last worked in version 8u101 ADDITIONAL REGRESSION INFORMATION: java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode) STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : public static void main(String[] args) { try { String xx = "http://coder_1.tanglei.name"; java.net.URI u = new java.net.URI(xx); System.out.println(u); System.out.println(u.getHost()); // null java.net.URL url = new java.net.URL(xx); System.out.println(url); System.out.println(url.getHost()); // coder_1.tanglei.name java.net.URI u2 = new java.net.URI(url.getProtocol(), url.getHost(), url.getPath(), ""); System.out.println(u2); } catch (Exception e){ System.out.println("exception got: " + e.getMessage()); } } EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - The same as URL ACTUAL - http://coder_1.tanglei.name null http://coder_1.tanglei.name coder_1.tanglei.name exception got: Illegal character in hostname at index 12: http://coder_1.tanglei.name# REPRODUCIBILITY : This bug can be reproduced always.
|