changeset 13697:1f801b99581a

8223892: Improved handling of jar files Reviewed-by: dfuchs, chegar, michaelm, rhalade, ahgross
author aefimov
date Tue, 25 Jun 2019 00:07:47 +0100
parents eeac0c758228
children 5c1c0eda1459
files src/share/classes/java/net/URL.java src/share/classes/sun/net/www/protocol/jar/Handler.java
diffstat 2 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/URL.java	Wed May 15 12:44:31 2019 -0700
+++ b/src/share/classes/java/net/URL.java	Tue Jun 25 00:07:47 2019 +0100
@@ -428,6 +428,16 @@
                 throw new MalformedURLException(s);
             }
         }
+        if ("jar".equalsIgnoreCase(protocol)) {
+            if (handler instanceof sun.net.www.protocol.jar.Handler) {
+                // URL.openConnection() would throw a confusing exception
+                // so generate a better exception here instead.
+                String s = ((sun.net.www.protocol.jar.Handler) handler).checkNestedProtocol(file);
+                if (s != null) {
+                    throw new MalformedURLException(s);
+                }
+            }
+        }
     }
 
     /**
--- a/src/share/classes/sun/net/www/protocol/jar/Handler.java	Wed May 15 12:44:31 2019 -0700
+++ b/src/share/classes/sun/net/www/protocol/jar/Handler.java	Tue Jun 25 00:07:47 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -121,6 +121,13 @@
         return h;
     }
 
+    public String checkNestedProtocol(String spec) {
+        if (spec.regionMatches(true, 0, "jar:", 0, 4)) {
+            return "Nested JAR URLs are not supported";
+        } else {
+            return null;
+        }
+    }
 
     @Override
     @SuppressWarnings("deprecation")
@@ -147,6 +154,12 @@
         }
         spec = spec.substring(start, limit);
 
+        String exceptionMessage = checkNestedProtocol(spec);
+        if (exceptionMessage != null) {
+            // NPE will be transformed into MalformedURLException by the caller
+            throw new NullPointerException(exceptionMessage);
+        }
+
         if (absoluteSpec) {
             file = parseAbsoluteSpec(spec);
         } else if (!refOnly) {