Field suid = cl.getDeclaredField("serialVersionUID"); suid.setAccessible(true);
final Field suid = cl.getDeclaredField("serialVersionUID"); AccessController.doPrivileged(new PrivilegedAction() { public Object run() { suid.setAccessible(true); return null; } });
  private long getClassUID(Class cl)  {    try      {	// Use getDeclaredField rather than getField, since serialVersionUID	// may not be public AND we only want the serialVersionUID of this	// class, not a superclass or interface.	Field suid = cl.getDeclaredField("serialVersionUID");	suid.setAccessible(true);	int modifiers = suid.getModifiers();	if (Modifier.isStatic(modifiers)	    && Modifier.isFinal(modifiers)	    && suid.getType() == Long.TYPE)	  return suid.getLong(null);      }    catch (NoSuchFieldException ignore)      {      }    catch (IllegalAccessException ignore)      {      }    // cl didn't define serialVersionUID, so we have to compute it    try      {	MessageDigest md;	try 	  {	    md = MessageDigest.getInstance("SHA");	  }	catch (NoSuchAlgorithmException e)	  {	    // If a provider already provides SHA, use it; otherwise, use this.	    Gnu gnuProvider = new Gnu();	    Security.addProvider(gnuProvider);	    md = MessageDigest.getInstance("SHA");	  }	DigestOutputStream digest_out =	  new DigestOutputStream(nullOutputStream, md);	DataOutputStream data_out = new DataOutputStream(digest_out);	data_out.writeUTF(cl.getName());	int modifiers = cl.getModifiers();	// just look at interesting bits	modifiers = modifiers & (Modifier.ABSTRACT | Modifier.FINAL				 | Modifier.INTERFACE | Modifier.PUBLIC);	data_out.writeInt(modifiers);	// Pretend that an array has no interfaces, because when array	// serialization was defined (JDK 1.1), arrays didn't have it.	if (! cl.isArray())	  {	    Class[] interfaces = cl.getInterfaces();	    Arrays.sort(interfaces, interfaceComparator);	    for (int i = 0; i < interfaces.length; i++)	      data_out.writeUTF(interfaces[i].getName());	  }	Field field;	Field[] fields = cl.getDeclaredFields();	Arrays.sort(fields, memberComparator);	for (int i = 0; i < fields.length; i++)	  {	    field = fields[i];	    modifiers = field.getModifiers();	    if (Modifier.isPrivate(modifiers)		&& (Modifier.isStatic(modifiers)		    || Modifier.isTransient(modifiers)))	      continue;	    data_out.writeUTF(field.getName());	    data_out.writeInt(modifiers);	    data_out.writeUTF(TypeSignature.getEncodingOfClass (field.getType()));	  }	// write class initializer method if present	if (VMObjectStreamClass.hasClassInitializer(cl))	  {	    data_out.writeUTF("<clinit>");	    data_out.writeInt(Modifier.STATIC);	    data_out.writeUTF("()V");	  }	Constructor constructor;	Constructor[] constructors = cl.getDeclaredConstructors();	Arrays.sort (constructors, memberComparator);	for (int i = 0; i < constructors.length; i++)	  {	    constructor = constructors[i];	    modifiers = constructor.getModifiers();	    if (Modifier.isPrivate(modifiers))	      continue;	    data_out.writeUTF("<init>");	    data_out.writeInt(modifiers);	    // the replacement of '/' with '.' was needed to make computed	    // SUID's agree with those computed by JDK	    data_out.writeUTF 	      (TypeSignature.getEncodingOfConstructor(constructor).replace('/','.'));	  }	Method method;	Method[] methods = cl.getDeclaredMethods();	Arrays.sort(methods, memberComparator);	for (int i = 0; i < methods.length; i++)	  {	    method = methods[i];	    modifiers = method.getModifiers();	    if (Modifier.isPrivate(modifiers))	      continue;	    data_out.writeUTF(method.getName());	    data_out.writeInt(modifiers);	    // the replacement of '/' with '.' was needed to make computed	    // SUID's agree with those computed by JDK	    data_out.writeUTF	      (TypeSignature.getEncodingOfMethod(method).replace('/', '.'));	  }	data_out.close();	byte[] sha = md.digest();	long result = 0;	int len = sha.length < 8 ? sha.length : 8;	for (int i = 0; i < len; i++)	  result += (long) (sha[i] & 0xFF) << (8 * i);	return result;      }    catch (NoSuchAlgorithmException e)      {	throw new RuntimeException	  ("The SHA algorithm was not found to use in computing the Serial Version UID for class "	   + cl.getName(), e);      }    catch (IOException ioe)      {	throw new RuntimeException(ioe);      }  }