changeset 52233:804fe860d8a3

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 174afa5802bd
children 2a4be9a65705
files src/java.base/share/classes/java/net/URL.java src/java.base/share/classes/sun/net/www/protocol/jar/Handler.java
diffstat 2 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/net/URL.java	Wed May 22 08:42:11 2019 -0700
+++ b/src/java.base/share/classes/java/net/URL.java	Tue Jun 25 00:07:47 2019 +0100
@@ -457,6 +457,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/java.base/share/classes/sun/net/www/protocol/jar/Handler.java	Wed May 22 08:42:11 2019 -0700
+++ b/src/java.base/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")
@@ -146,6 +153,12 @@
                 : false;
         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) {