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

Specification of some BasicPermission method does not fit with implementation

XMLWordPrintable

    • b16
    • x86
    • linux
    • Verified

      As result for fix of CR 6268673 special handling of "exitVM" permission name is added to BasicPermission.

      First of all I'm not sure BasicPermission is best place for fix of CR 6268673.

      Any way even if it is necessary to change BasicPermission then it should be reflected in specification.

      It looks like 'hashCode' and 'equals' method are affected:
      -------------------
      public int hashCode()

          Returns the hash code value for this object. The hash code used is the hash code of the name, that is, getName().hashCode(), where getName is from the Permission superclass.
      --------------------

      It means following application should output same hash codes for permission and name:

      ---------------
      import java.security.BasicPermission;

      public class HashBP {
          public static void main(String[] args) {
              BasicPermission bp = new BasicPermission(args[0]){};
              System.out.println("BP hashCode: " + bp.hashCode());
              System.out.println("name hashCode: " + bp.getName().hashCode());
          }
      }
      -----------------

      However:

      > /opt/jdk1.6.0/bin/java HashBP exitVM
      BP hashCode: -2122696495
      name hashCode: -1289358251


      Similarly:

      ---------------------
      public boolean equals(Object obj)

          Checks two BasicPermission objects for equality. Checks that obj's class is the same as this object's class and has the same name as this object.

          Specified by:
              equals in class Permission

          Parameters:
              obj - the object we are testing for equality with this object.
          Returns:
              true if obj is a BasicPermission, and has the same name as this BasicPermission object, false otherwise.
      ---------------------

      It means following application should output same values for permission and name comparisons:

      ---------------

      import java.security.BasicPermission;

      class BP extends BasicPermission {
          BP(String name) {
              super(name);
          }
      }

      public class EqualsBP {
          public static void main(String[] args) {
              BasicPermission bp1 = new BP(args[0]);
              BasicPermission bp2 = new BP(args[1]);
              System.out.println("BP equals: " + bp1.equals(bp2));
              System.out.println("name equals: " + bp1.getName().equals(bp2.getName()));
          }
      }

      -----------------

      However:
      > /opt/jdk1.6.0/bin/java EqualsBP exitVM exitVM.*
      BP equals: true
      name equals: false

            weijun Weijun Wang
            sreznick Sergey Reznick (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: