summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/security/Signature.java2
-rw-r--r--luni/src/test/java/org/apache/harmony/security/tests/java/security/Signature2Test.java10
2 files changed, 11 insertions, 1 deletions
diff --git a/luni/src/main/java/java/security/Signature.java b/luni/src/main/java/java/security/Signature.java
index 7dd7d93..a39d59b 100644
--- a/luni/src/main/java/java/security/Signature.java
+++ b/luni/src/main/java/java/security/Signature.java
@@ -703,7 +703,7 @@ public abstract class Signature extends SignatureSpi {
@Override
public Object clone() throws CloneNotSupportedException {
- SignatureSpi spi = (SignatureSpi) spiImpl.clone();
+ SignatureSpi spi = spiImpl != null ? (SignatureSpi) spiImpl.clone() : null;
return new SignatureImpl(getAlgorithm(), getProvider(), spi);
}
diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/Signature2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/Signature2Test.java
index 7886e3e..ad084e1 100644
--- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/Signature2Test.java
+++ b/luni/src/test/java/org/apache/harmony/security/tests/java/security/Signature2Test.java
@@ -68,7 +68,17 @@ public class Signature2Test extends junit.framework.TestCase {
* java.security.Signature#clone()
*/
public void test_clone() throws Exception {
+ // A Signature may be cloneable according to the API, in practice the implementation isn't
+ // once it has been initialized. Checking for runtime exceptions rather than useful
+ // behavior.
Signature s = Signature.getInstance("DSA");
+ Signature clone = (Signature) s.clone();
+ assertNotNull(clone);
+ assertEquals(s.getAlgorithm(), clone.getAlgorithm());
+ assertEquals(s.getProvider(), clone.getProvider());
+
+ KeyPair keyPair = getDsaKeys();
+ s.initSign(keyPair.getPrivate());
try {
s.clone();
fail();