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

JCK regression: URL.equals requires permission to access network

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.0
    • 1.2.0
    • core-libs
    • 1.2fcs
    • sparc
    • solaris_2.5
    • Not verified



      Name: mgC56079 Date: 10/02/98



      java.net.URL.equals requires SocketPermission (host resolve) in jdk1.2fcs.
      This is not documented and causes JCK test failures in restricted environment
      (appletviewer).

      Here is a minimized test demonstrating the problem:
      ====== URLTest.java ========
      import java.net.URL;

      public class URLTest extends java.applet.Applet {

          public void init() {
              try {
                  URL url1=new URL("http://some.host/index.html");
                  URL url2=new URL("http://some.host/index.html");
                  System.out.println(url1.equals(url2));
                  System.out.println("OKAY");
              }
              catch (Exception e) {
                  e.printStackTrace();
              }
          }

      }
      ====== URLTest.html ========
      <applet
          code="URLTest.class"
          width=600 height=400
      >
      [[You need a Java-aware browser to see the JavaTest Slave applet.]]
      </applet>
      ====== Sample run (jdk1.1.7, jdk1.2beta4) =========
      % appletviewer URLTest.html
      true
      OKAY
      ^C
      ====== Sample run (jdk1.2fcsL - REGRESSION) =========
      % appletviewer URLTest.html
      java.security.AccessControlException: access denied (java.net.SocketPermission some.host resolve)
      at java.security.AccessControlContext.checkPermission(Compiled Code)
      at java.security.AccessController.checkPermission(Compiled Code)
      at java.lang.SecurityManager.checkPermission(Compiled Code)
      at java.lang.SecurityManager.checkConnect(Compiled Code)
      at java.net.InetAddress.getAllByName0(Compiled Code)
      at java.net.InetAddress.getAllByName0(Compiled Code)
      at java.net.InetAddress.getByName(Compiled Code)
      at java.net.URL.getHostAddress(Compiled Code)
      at java.net.URL.hostsEqual(Compiled Code)
      at java.net.URL.sameFile(Compiled Code)
      at java.net.URL.equals(Compiled Code)
      at URLTest.init(Compiled Code)
      at sun.applet.AppletPanel.run(Compiled Code)
      at java.lang.Thread.run(Compiled Code)
      ^C
      ===========

      ==== Here is the spec for URL.equals ====
          /**
           * Compares two URLs. The result is <code>true</code> if and
           * only if the argument is not <code>null</code> and is a
           * <code>URL</code> object that represents the same
           * <code>URL</code> as this object. Two URL objects are equal if
           * they have the same protocol and reference the same host, the
           * same port number on the host, and the same file and anchor on
           * the host.
           *
           * @param obj the URL to compare against.
           * @return <code>true</code> if the objects are the same;
           * <code>false</code> otherwise.
           */
          public boolean equals(Object obj)

      Note: the two URLs in the example are exactly equal according to the spec
      so true should be returned.

      ======================================================================

            jdn Jeffrey Nisewanger (Inactive)
            mgorshen Mikhail Gorshenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: