Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8224973

URLStreamHandler.openConnection(URL,Proxy) - spec and implementation mismatch

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6.0, 5.0, 7, 8, 9, 10, 11, 12, 13
    • Fix Version/s: 13
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b24

      Backports

        Description

        java.net.URLStreamHandler::openConnection(java.net.URL,java.net.Proxy)
        implementation says :
        throw new UnsupportedOperationException("Method not implemented.");

        but spec says :
        /**
             * Same as openConnection(URL), except that the connection will be
             * made through the specified proxy; Protocol handlers that do not
             * support proxying will ignore the proxy parameter and make a
             * normal connection.
             *
             * Calling this method preempts the system's default
             * {@link java.net.ProxySelector ProxySelector} settings.
             *
             * @param u the URL that this connects to.
             * @param p the proxy through which the connection will be made.
             * If direct connection is desired, Proxy.NO_PROXY
             * should be specified.
             * @return a {@code URLConnection} object for the {@code URL}.
             * @exception IOException if an I/O error occurs while opening the
             * connection.
             * @exception IllegalArgumentException if either u or p is null,
             * or p has the wrong type.
             * @exception UnsupportedOperationException if the subclass that
             * implements the protocol doesn't support this method.
             * @since 1.5
             */

        So following is expected to thrown IllegalArgumentException but UnsupportedOperationException is the one that is always thrown

        CustomURLStreamHandler customURLStreamHandler = new CustomURLStreamHandler();
        customURLStreamHandler.openConnection(null, null);
        // above should throw IllegalArgumentException

        class CustomURLStreamHandler extends URLStreamHandler {
            public CustomURLStreamHandler() {
            }

            public URLConnection openConnection(URL var1) {
                return null;
            }

            public URLConnection openConnection(URL url, Proxy proxy) throws IOException {
                return super.openConnection(url, proxy);
            }
        }

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                chegar Chris Hegarty
                Reporter:
                msomani Mohit Somani (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: