diff --git a/src/share/classes/java/net/URL.java b/src/share/classes/java/net/URL.java index be6c294d191588c49e493d8ecce2f678b36b38e2..bbe87b62722cc6e6899f18bfaa36545dd4c97df1 100644 --- a/src/share/classes/java/net/URL.java +++ b/src/share/classes/java/net/URL.java @@ -428,6 +428,16 @@ public final class URL implements java.io.Serializable { 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); + } + } + } } /** diff --git a/src/share/classes/sun/net/www/protocol/jar/Handler.java b/src/share/classes/sun/net/www/protocol/jar/Handler.java index 8e9f8e3a35f2c9403295ad0aafd4fe151d41f5fb..4a3ae7e8aebe2d7c9e24d2c632c1b48cec99a7e4 100644 --- a/src/share/classes/sun/net/www/protocol/jar/Handler.java +++ b/src/share/classes/sun/net/www/protocol/jar/Handler.java @@ -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 @@ public class Handler extends java.net.URLStreamHandler { 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 @@ public class Handler extends java.net.URLStreamHandler { } 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) {