Index: modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/cert/CertificateFactory_ImplTest.java =================================================================== --- modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/cert/CertificateFactory_ImplTest.java (revision 420453) +++ modules/security/src/test/impl/java/org/apache/harmony/security/tests/java/security/cert/CertificateFactory_ImplTest.java (working copy) @@ -22,15 +22,19 @@ package org.apache.harmony.security.tests.java.security.cert; import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.security.KeyFactory; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; +import java.security.cert.CRLException; +import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509CRL; import java.security.cert.X509Certificate; import java.security.spec.X509EncodedKeySpec; import java.util.Collection; import java.util.Iterator; +import java.util.List; import org.apache.harmony.luni.util.Base64; import junit.framework.TestCase; @@ -163,6 +167,19 @@ } /** + * generateCRLs(InputStream inStream) method testing. + */ + public void testGenerateCRLs2() throws Exception { + try { + CertificateFactory.getInstance("X.509") + .generateCRL((InputStream) null); + fail("Expected exception was not thrown."); + } catch (CRLException e) { + // expected + } + } + + /** * generateCertificates method testing. */ public void testGenerateCertificates() throws Exception { @@ -187,6 +204,19 @@ } /** + * generateCertificates(InputStream inStream) method testing. + */ + public void testGenerateCertificates2() throws Exception { + try { + CertificateFactory.getInstance("X.509") + .generateCertificates(null); + fail("Expected exception was not thrown."); + } catch (CertificateException e) { + // expected + } + } + + /** * generateCertificates method testing. */ public void testGenerateCertPath() throws Exception { @@ -210,4 +240,69 @@ } } + /** + * generateCertPath(InputStream inStream, String encoding) method testing. + */ + public void testGenerateCertPath1() throws Exception { + try { + CertificateFactory.getInstance("X.509") + .generateCertPath((InputStream) null, "PkiPath"); + fail("Expected exception was not thrown."); + } catch (CertificateException e) { + // expected + } + } + + /** + * generateCertPath(List certificates) method + * testing. + */ + public void testGenerateCertPath2() throws Exception { + try { + CertificateFactory.getInstance("X.509") + .generateCertPath((List) null); + fail("Expected exception was not thrown."); + } catch (NullPointerException e) { + // expected + } + } + + /** + * generateCertPath(InputStream inStream) method testing. + */ + public void testGenerateCertPath3() throws Exception { + try { + CertificateFactory.getInstance("X.509") + .generateCertPath((InputStream) null); + fail("Expected exception was not thrown."); + } catch (CertificateException e) { + // expected + } + } + + /** + * generateCertificate(InputStream inStream) method testing. + */ + public void testGenerateCertificate() throws Exception { + try { + CertificateFactory.getInstance("X.509") + .generateCertificate(null); + fail("Expected exception was not thrown."); + } catch (CertificateException e) { + // expected + } + } + + /** + * generateCRL(InputStream inStream) method testing. + */ + public void testGenerateCRL() throws Exception { + try { + CertificateFactory.getInstance("X.509") + .generateCRL((InputStream) null); + fail("Expected exception was not thrown."); + } catch (CRLException e) { + // expected + } + } } Index: modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CertFactoryImpl.java =================================================================== --- modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CertFactoryImpl.java (revision 420453) +++ modules/security/src/main/java/common/org/apache/harmony/security/provider/cert/X509CertFactoryImpl.java (working copy) @@ -83,6 +83,9 @@ */ public Certificate engineGenerateCertificate(InputStream inStream) throws CertificateException { + if (inStream == null) { + throw new CertificateException("Input stream should not be null."); + } try { if (!inStream.markSupported()) { // create the mark supporting wrapper @@ -159,6 +162,9 @@ public Collection engineGenerateCertificates(InputStream inStream) throws CertificateException { + if (inStream == null) { + throw new CertificateException("Input stream should not be null."); + } ArrayList result = new ArrayList(); try { if (!inStream.markSupported()) { @@ -232,6 +238,9 @@ */ public CRL engineGenerateCRL(InputStream inStream) throws CRLException { + if (inStream == null) { + throw new CRLException("Input stream should not be null."); + } try { if (!inStream.markSupported()) { // create the mark supporting wrapper