Skip to content

Commit 888c30c

Browse files
committed
[fix] null guard for public key in PKey#toJava
1 parent bafe6c9 commit 888c30c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/main/java/org/jruby/ext/openssl/PKey.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ public Object toJava(final Class target) {
269269
if (target.isAssignableFrom(PublicKey.class) || Key.class.isAssignableFrom(target)) {
270270
// default is public key, also want to_java() as well as to_java(java.lang.Object) to end up here
271271
final PublicKey key = getPublicKey();
272+
if (key == null) {
273+
throw getRuntime().newRuntimeError("public key not available, to convert to " + target);
274+
}
272275
if (target.isInstance(key)) return key;
273276
throw getRuntime().newTypeError("cannot convert public key of type " + key.getClass() + " to " + target);
274277
}

0 commit comments

Comments
 (0)