src/java.security.jgss/share/classes/sun/security/krb5/PrincipalName.java

Print this page
rev 12972 : 8140606: Update library code to use internal Unsafe
Reviewed-by: duke


 170             if (s == null) {
 171                 throw new IllegalArgumentException("Null nameString not allowed");
 172             }
 173             if (s.isEmpty()) {
 174                 throw new IllegalArgumentException("Empty nameString not allowed");
 175             }
 176         }
 177     }
 178 
 179     public Object clone() {
 180         try {
 181             PrincipalName pName = (PrincipalName) super.clone();
 182             UNSAFE.putObject(this, NAME_STRINGS_OFFSET, nameStrings.clone());
 183             return pName;
 184         } catch (CloneNotSupportedException ex) {
 185             throw new AssertionError("Should never happen");
 186         }
 187     }
 188 
 189     private static final long NAME_STRINGS_OFFSET;
 190     private static final sun.misc.Unsafe UNSAFE;
 191     static {
 192         try {
 193             sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe();
 194             NAME_STRINGS_OFFSET = unsafe.objectFieldOffset(
 195                     PrincipalName.class.getDeclaredField("nameStrings"));
 196             UNSAFE = unsafe;
 197         } catch (ReflectiveOperationException e) {
 198             throw new Error(e);
 199         }
 200     }
 201 
 202     @Override
 203     public boolean equals(Object o) {
 204         if (this == o) {
 205             return true;
 206         }
 207         if (o instanceof PrincipalName) {
 208             PrincipalName other = (PrincipalName)o;
 209             return nameRealm.equals(other.nameRealm) &&
 210                     Arrays.equals(nameStrings, other.nameStrings);
 211         }
 212         return false;
 213     }




 170             if (s == null) {
 171                 throw new IllegalArgumentException("Null nameString not allowed");
 172             }
 173             if (s.isEmpty()) {
 174                 throw new IllegalArgumentException("Empty nameString not allowed");
 175             }
 176         }
 177     }
 178 
 179     public Object clone() {
 180         try {
 181             PrincipalName pName = (PrincipalName) super.clone();
 182             UNSAFE.putObject(this, NAME_STRINGS_OFFSET, nameStrings.clone());
 183             return pName;
 184         } catch (CloneNotSupportedException ex) {
 185             throw new AssertionError("Should never happen");
 186         }
 187     }
 188 
 189     private static final long NAME_STRINGS_OFFSET;
 190     private static final jdk.internal.misc.Unsafe UNSAFE;
 191     static {
 192         try {
 193             jdk.internal.misc.Unsafe unsafe = jdk.internal.misc.Unsafe.getUnsafe();
 194             NAME_STRINGS_OFFSET = unsafe.objectFieldOffset(
 195                     PrincipalName.class.getDeclaredField("nameStrings"));
 196             UNSAFE = unsafe;
 197         } catch (ReflectiveOperationException e) {
 198             throw new Error(e);
 199         }
 200     }
 201 
 202     @Override
 203     public boolean equals(Object o) {
 204         if (this == o) {
 205             return true;
 206         }
 207         if (o instanceof PrincipalName) {
 208             PrincipalName other = (PrincipalName)o;
 209             return nameRealm.equals(other.nameRealm) &&
 210                     Arrays.equals(nameStrings, other.nameStrings);
 211         }
 212         return false;
 213     }