< prev index next >

src/share/classes/sun/security/x509/X500Name.java

Print this page
rev 1387 : 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
Reviewed-by: xuelei, mullan
Contributed-by: alexandre.boulgakov@oracle.com

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -25,18 +25,16 @@
 
 package sun.security.x509;
 
 import java.lang.reflect.*;
 import java.io.IOException;
-import java.io.StringReader;
 import java.security.PrivilegedExceptionAction;
 import java.security.AccessController;
 import java.security.Principal;
 import java.util.*;
 
 import sun.security.util.*;
-import sun.security.pkcs.PKCS9Attribute;
 import javax.security.auth.x500.X500Principal;
 
 /**
  * Note:  As of 1.4, the public class,
  * javax.security.auth.x500.X500Principal,

@@ -1368,11 +1366,11 @@
     }
 
     /**
      * Constructor object for use by asX500Principal().
      */
-    private static final Constructor principalConstructor;
+    private static final Constructor<X500Principal> principalConstructor;
 
     /**
      * Field object for use by asX500Name().
      */
     private static final Field principalField;

@@ -1383,22 +1381,25 @@
      */
     static {
         PrivilegedExceptionAction<Object[]> pa =
                 new PrivilegedExceptionAction<Object[]>() {
             public Object[] run() throws Exception {
-                Class pClass = X500Principal.class;
-                Class[] args = new Class[] {X500Name.class};
-                Constructor cons = ((Class<?>)pClass).getDeclaredConstructor(args);
+                Class<X500Principal> pClass = X500Principal.class;
+                Class<?>[] args = new Class<?>[] { X500Name.class };
+                Constructor<X500Principal> cons = pClass.getDeclaredConstructor(args);
                 cons.setAccessible(true);
                 Field field = pClass.getDeclaredField("thisX500Name");
                 field.setAccessible(true);
                 return new Object[] {cons, field};
             }
         };
         try {
             Object[] result = AccessController.doPrivileged(pa);
-            principalConstructor = (Constructor)result[0];
+            @SuppressWarnings("unchecked")
+            Constructor<X500Principal> constr =
+                    (Constructor<X500Principal>)result[0];
+            principalConstructor = constr;
             principalField = (Field)result[1];
         } catch (Exception e) {
             throw (InternalError)new InternalError("Could not obtain "
                 + "X500Principal access").initCause(e);
         }

@@ -1412,12 +1413,11 @@
      */
     public X500Principal asX500Principal() {
         if (x500Principal == null) {
             try {
                 Object[] args = new Object[] {this};
-                x500Principal =
-                        (X500Principal)principalConstructor.newInstance(args);
+                x500Principal = principalConstructor.newInstance(args);
             } catch (Exception e) {
                 throw new RuntimeException("Unexpected exception", e);
             }
         }
         return x500Principal;
< prev index next >