changeset 42991:174ff3aebaf7

8172003: getInstance() with unknown provider throws NPE Reviewed-by: mullan
author apetcher
date Wed, 04 Jan 2017 08:06:15 -0500
parents 9edd5241610a
children c692f1d73e14
files jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/TransformService.java jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/XMLSignatureFactory.java jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/keyinfo/KeyInfoFactory.java jdk/test/javax/xml/crypto/dsig/TransformService/UnknownProvider.java jdk/test/javax/xml/crypto/dsig/XMLSignatureFactory/UnknownProvider.java jdk/test/javax/xml/crypto/dsig/keyinfo/KeyInfoFactory/UnknownProvider.java
diffstat 6 files changed, 155 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/TransformService.java	Tue Jan 03 22:26:51 2017 -0800
+++ b/jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/TransformService.java	Wed Jan 04 08:06:15 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, 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
@@ -275,6 +275,10 @@
             dom = true;
         }
         Provider p = Security.getProvider(provider);
+        if (p == null) {
+            throw new NoSuchProviderException("No such provider: " +
+                                              provider);
+        }
         Service s = p.getService("TransformService", algorithm);
         if (s != null) {
             String value = s.getAttribute("MechanismType");
--- a/jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/XMLSignatureFactory.java	Tue Jan 03 22:26:51 2017 -0800
+++ b/jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/XMLSignatureFactory.java	Wed Jan 04 08:06:15 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, 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
@@ -305,6 +305,10 @@
         }
 
         Provider p = Security.getProvider(provider);
+        if (p == null) {
+            throw new NoSuchProviderException("No such provider: " +
+                                              provider);
+        }
         Service s = p.getService("XMLSignatureFactory", mechanismType);
         if (s != null) {
             Object obj = null;
--- a/jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/keyinfo/KeyInfoFactory.java	Tue Jan 03 22:26:51 2017 -0800
+++ b/jdk/src/java.xml.crypto/share/classes/javax/xml/crypto/dsig/keyinfo/KeyInfoFactory.java	Wed Jan 04 08:06:15 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2017, 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
@@ -258,6 +258,10 @@
             throw new NoSuchProviderException();
         }
         Provider p = Security.getProvider(provider);
+        if (p == null) {
+            throw new NoSuchProviderException("No such provider: " +
+                                              provider);
+        }
         Service s = p.getService("KeyInfoFactory", mechanismType);
         if (s != null) {
             Object obj = null;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/xml/crypto/dsig/TransformService/UnknownProvider.java	Wed Jan 04 08:06:15 2017 -0500
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8172003
+ * @summary Test that TransformService.getInstance() throws a
+ *   NoSuchProviderException when provider is unknown
+ * @run main UnknownProvider
+ */
+
+import javax.xml.crypto.dsig.TransformService;
+import javax.xml.crypto.dsig.Transform;
+import java.security.NoSuchProviderException;
+import java.security.NoSuchAlgorithmException;
+
+public class UnknownProvider {
+
+    public static void main(String[] args) throws NoSuchAlgorithmException {
+       try {
+           TransformService ts = TransformService.getInstance(
+               Transform.BASE64, "DOM", "SomeProviderThatDoesNotExist");
+       }
+       catch(NoSuchProviderException e) {
+           // this is expected
+       }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/xml/crypto/dsig/XMLSignatureFactory/UnknownProvider.java	Wed Jan 04 08:06:15 2017 -0500
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8172003
+ * @summary Test that XMLSignatureFactory.getInstance() throws a
+ *   NoSuchProviderException when provider is unknown
+ * @run main UnknownProvider
+ */
+
+import javax.xml.crypto.dsig.XMLSignatureFactory;
+import java.security.NoSuchProviderException;
+
+public class UnknownProvider {
+
+    public static void main(String[] args) {
+       try {
+            XMLSignatureFactory sf = XMLSignatureFactory.getInstance(
+                "DOM", "SomeProviderThatDoesNotExist");
+       }
+       catch(NoSuchProviderException e) {
+            // this is expected
+       }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/xml/crypto/dsig/keyinfo/KeyInfoFactory/UnknownProvider.java	Wed Jan 04 08:06:15 2017 -0500
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2017, 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.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * @test
+ * @bug 8172003
+ * @summary Test that KeyInfoFactory.getInstance() throws a
+ *   NoSuchProviderException when provider is unknown
+ * @run main UnknownProvider
+ */
+
+import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
+import java.security.NoSuchProviderException;
+
+public class UnknownProvider {
+
+    public static void main(String[] args) {
+        try {
+            KeyInfoFactory fac = KeyInfoFactory.getInstance(
+                "DOM", "SomeProviderThatDoesNotExist");
+        }
+        catch(NoSuchProviderException e) {
+            // this is expected
+        }
+    }
+}