1+ /*
2+ * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+ *
5+ * This code is free software; you can redistribute it and/or modify it
6+ * under the terms of the GNU General Public License version 2 only, as
7+ * published by the Free Software Foundation.
8+ *
9+ * This code is distributed in the hope that it will be useful, but WITHOUT
10+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+ * version 2 for more details (a copy is included in the LICENSE file that
13+ * accompanied this code).
14+ *
15+ * You should have received a copy of the GNU General Public License version
16+ * 2 along with this work; if not, write to the Free Software Foundation,
17+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+ *
19+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+ * or visit www.oracle.com if you need additional information or have any
21+ * questions.
22+ */
23+
24+ /*
25+ * @test
26+ * @bug 8367049
27+ * @summary URLPermission must reject empty/missing host authority with IAE (no SIOOBE)
28+ * @run testng EmptyAuthorityTest
29+ */
30+
31+ import java .net .URLPermission ;
32+ import org .testng .Assert ;
33+ import org .testng .annotations .DataProvider ;
34+ import org .testng .annotations .Test ;
35+
36+ public class EmptyAuthorityTest {
37+
38+ @ DataProvider (name = "badUrls" )
39+ public Object [][] badUrls () {
40+ return new Object [][]{
41+ { "http:///path" }, // empty authority
42+ { "https:///x" }, // empty authority
43+ { "http://@/x" }, // userinfo + empty host
44+ { "http://user@/x" }, // userinfo + empty host
45+ { "http://:80/x" }, // port with no host
46+ { "http://[]/x" } // empty IPv6 literal
47+ };
48+ }
49+
50+ @ DataProvider (name = "goodUrls" )
51+ public Object [][] goodUrls () {
52+ return new Object [][]{
53+ { "http://example.com/x" },
54+ { "http://example.com:80/x" },
55+ { "http://[::1]/x" },
56+ { "http://[::1]:8080/x" }
57+ };
58+ }
59+
60+ @ Test (dataProvider = "badUrls" )
61+ public void rejectsEmptyOrMalformedAuthority (String url ) {
62+ Assert .expectThrows (IllegalArgumentException .class , () -> new URLPermission (url ));
63+ }
64+
65+ @ Test (dataProvider = "goodUrls" )
66+ public void acceptsValidAuthorities (String url ) {
67+ new URLPermission (url ); // should not throw
68+ }
69+ }
0 commit comments