170170 * the recommendations advised in <a
171171 * href="https://tools.ietf.org/html/rfc3986#section-7">RFC3986,
172172 * Section 7, Security Considerations</a>.
173+ * <p>
174+ * All {@code URL} constructors may throw {@link MalformedURLException}.
175+ * In particular, if the underlying {@link URLStreamHandler}
176+ * implementation rejects, or is known to reject, any of the parameters,
177+ * {@link MalformedURLException} may be thrown.
178+ * Typically, a constructor that calls the stream handler's {@linkplain
179+ * URLStreamHandler#parseURL(URL, String, int, int) parseURL method} may
180+ * throw {@code MalformedURLException} if the underlying stream handler
181+ * implementation of that method throws {@code IllegalArgumentException}.
182+ * However, which checks are performed, or not, by the stream handlers
183+ * is implementation dependent, and callers should not rely on such
184+ * checks for full URL validation.
173185 *
174186 * @author James Gosling
175187 * @since 1.0
@@ -352,7 +364,9 @@ public final class URL implements java.io.Serializable {
352364 * @param port the port number on the host.
353365 * @param file the file on the host
354366 * @throws MalformedURLException if an unknown protocol or the port
355- * is a negative number other than -1
367+ * is a negative number other than -1, or if the
368+ * underlying stream handler implementation rejects,
369+ * or is known to reject, the {@code URL}
356370 * @see java.lang.System#getProperty(java.lang.String)
357371 * @see java.net.URL#setURLStreamHandlerFactory(
358372 * java.net.URLStreamHandlerFactory)
@@ -380,7 +394,9 @@ public URL(String protocol, String host, int port, String file)
380394 * @param protocol the name of the protocol to use.
381395 * @param host the name of the host.
382396 * @param file the file on the host.
383- * @throws MalformedURLException if an unknown protocol is specified.
397+ * @throws MalformedURLException if an unknown protocol is specified,
398+ * or if the underlying stream handler implementation
399+ * rejects, or is known to reject, the {@code URL}
384400 * @see java.net.URL#URL(java.lang.String, java.lang.String,
385401 * int, java.lang.String)
386402 */
@@ -415,7 +431,9 @@ public URL(String protocol, String host, String file)
415431 * @param file the file on the host
416432 * @param handler the stream handler for the URL.
417433 * @throws MalformedURLException if an unknown protocol or the port
418- * is a negative number other than -1
434+ * is a negative number other than -1,
435+ * or if the underlying stream handler implementation
436+ * rejects, or is known to reject, the {@code URL}
419437 * @throws SecurityException
420438 * if a security manager exists and its
421439 * {@code checkPermission} method doesn't allow
@@ -510,7 +528,10 @@ public URL(String protocol, String host, int port, String file,
510528 * @throws MalformedURLException if no protocol is specified, or an
511529 * unknown protocol is found, or {@code spec} is {@code null},
512530 * or the parsed URL fails to comply with the specific syntax
513- * of the associated protocol.
531+ * of the associated protocol, or the
532+ * underlying stream handler's {@linkplain
533+ * URLStreamHandler#parseURL parseURL method} throws
534+ * {@code IllegalArgumentException}
514535 * @see java.net.URL#URL(java.net.URL, java.lang.String)
515536 */
516537 public URL (String spec ) throws MalformedURLException {
@@ -522,7 +543,7 @@ public URL(String spec) throws MalformedURLException {
522543 *
523544 * The new URL is created from the given context URL and the spec
524545 * argument as described in
525- * RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
546+ * RFC2396 "Uniform Resource Identifiers : Generic Syntax" :
526547 * <blockquote><pre>
527548 * <scheme>://<authority><path>?<query>#<fragment>
528549 * </pre></blockquote>
@@ -554,12 +575,19 @@ public URL(String spec) throws MalformedURLException {
554575 * <p>
555576 * For a more detailed description of URL parsing, refer to RFC2396.
556577 *
578+ * @implSpec Parsing the URL includes calling the {@link
579+ * URLStreamHandler#parseURL(URL, String, int, int) parseURL} method on the
580+ * selected handler.
581+ *
557582 * @param context the context in which to parse the specification.
558583 * @param spec the {@code String} to parse as a URL.
559584 * @throws MalformedURLException if no protocol is specified, or an
560585 * unknown protocol is found, or {@code spec} is {@code null},
561586 * or the parsed URL fails to comply with the specific syntax
562- * of the associated protocol.
587+ * of the associated protocol, or the
588+ * underlying stream handler's {@linkplain
589+ * URLStreamHandler#parseURL parseURL method} throws
590+ * {@code IllegalArgumentException}
563591 * @see java.net.URL#URL(java.lang.String, java.lang.String,
564592 * int, java.lang.String)
565593 * @see java.net.URLStreamHandler
@@ -575,13 +603,20 @@ public URL(URL context, String spec) throws MalformedURLException {
575603 * within a specified context. If the handler is null, the parsing
576604 * occurs as with the two argument constructor.
577605 *
606+ * @implSpec Parsing the URL includes calling the {@link
607+ * URLStreamHandler#parseURL(URL, String, int, int) parseURL} method on the
608+ * selected handler.
609+ *
578610 * @param context the context in which to parse the specification.
579611 * @param spec the {@code String} to parse as a URL.
580612 * @param handler the stream handler for the URL.
581613 * @throws MalformedURLException if no protocol is specified, or an
582614 * unknown protocol is found, or {@code spec} is {@code null},
583615 * or the parsed URL fails to comply with the specific syntax
584- * of the associated protocol.
616+ * of the associated protocol, or the
617+ * underlying stream handler's {@linkplain
618+ * URLStreamHandler#parseURL(URL, String, int, int)
619+ * parseURL method} throws {@code IllegalArgumentException}
585620 * @throws SecurityException
586621 * if a security manager exists and its
587622 * {@code checkPermission} method doesn't allow
0 commit comments