< prev index next >

src/java.base/share/classes/javax/security/cert/X509Certificate.java

Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD


 193      * @param certData a byte array containing the DER-encoded
 194      *        certificate.
 195      * @return an X509Certificate object initialized with the data
 196      *         from {@code certData}.
 197      * @exception CertificateException if a class initialization
 198      *            or certificate parsing error occurs.
 199      */
 200     public static final X509Certificate getInstance(byte[] certData)
 201     throws CertificateException {
 202         return getInst((Object)certData);
 203     }
 204 
 205     private static final X509Certificate getInst(Object value)
 206     throws CertificateException {
 207         /*
 208          * This turns out not to work for now. To run under JDK1.2 we would
 209          * need to call beginPrivileged() but we can't do that and run
 210          * under JDK1.1.
 211          */
 212         String className = X509Provider;
 213         if (className == null || className.length() == 0) {
 214             // shouldn't happen, but assume corrupted properties file
 215             // provide access to sun implementation
 216             className = "com.sun.security.cert.internal.x509.X509V1CertImpl";
 217         }
 218         try {
 219             Class<?>[] params = null;
 220             if (value instanceof InputStream) {
 221                 params = new Class<?>[] { InputStream.class };
 222             } else if (value instanceof byte[]) {
 223                 params = new Class<?>[] { value.getClass() };
 224             } else
 225                 throw new CertificateException("Unsupported argument type");
 226             Class<?> certClass = Class.forName(className);
 227 
 228             // get the appropriate constructor and instantiate it
 229             Constructor<?> cons = certClass.getConstructor(params);
 230 
 231             // get a new instance
 232             Object obj = cons.newInstance(new Object[] {value});
 233             return (X509Certificate)obj;




 193      * @param certData a byte array containing the DER-encoded
 194      *        certificate.
 195      * @return an X509Certificate object initialized with the data
 196      *         from {@code certData}.
 197      * @exception CertificateException if a class initialization
 198      *            or certificate parsing error occurs.
 199      */
 200     public static final X509Certificate getInstance(byte[] certData)
 201     throws CertificateException {
 202         return getInst((Object)certData);
 203     }
 204 
 205     private static final X509Certificate getInst(Object value)
 206     throws CertificateException {
 207         /*
 208          * This turns out not to work for now. To run under JDK1.2 we would
 209          * need to call beginPrivileged() but we can't do that and run
 210          * under JDK1.1.
 211          */
 212         String className = X509Provider;
 213         if (className == null || className.isEmpty()) {
 214             // shouldn't happen, but assume corrupted properties file
 215             // provide access to sun implementation
 216             className = "com.sun.security.cert.internal.x509.X509V1CertImpl";
 217         }
 218         try {
 219             Class<?>[] params = null;
 220             if (value instanceof InputStream) {
 221                 params = new Class<?>[] { InputStream.class };
 222             } else if (value instanceof byte[]) {
 223                 params = new Class<?>[] { value.getClass() };
 224             } else
 225                 throw new CertificateException("Unsupported argument type");
 226             Class<?> certClass = Class.forName(className);
 227 
 228             // get the appropriate constructor and instantiate it
 229             Constructor<?> cons = certClass.getConstructor(params);
 230 
 231             // get a new instance
 232             Object obj = cons.newInstance(new Object[] {value});
 233             return (X509Certificate)obj;


< prev index next >