Skip to content

Commit 0bd2bd4

Browse files
committed
avoid NPE due version field in X509Cert - make sure it's treated as 0 (fixes #78)
1 parent 5e4f2c4 commit 0bd2bd4

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public IRubyObject to_text(final ThreadContext context) {
310310

311311
text.append("Certificate:\n");
312312
text.append(S20,0,4).append("Data:\n");
313-
final int version = RubyNumeric.fix2int(this.version);
313+
final int version = this.version == null ? 0 : RubyNumeric.fix2int(this.version);
314314
text.append(S20,0,8).append("Version: ").append( version + 1 ).
315315
append(" (0x").append( Integer.toString( version, 16 ) ).append(")\n");
316316
text.append(S20,0,8).append("Serial Number:\n");
@@ -382,12 +382,12 @@ public IRubyObject inspect() {
382382

383383
@JRubyMethod
384384
public IRubyObject version() {
385-
return version;
385+
return version != null ? version : ( version = getRuntime().newFixnum(0) );
386386
}
387387

388388
@JRubyMethod(name = "version=")
389389
public IRubyObject set_version(final IRubyObject version) {
390-
if ( ! version.equals(this.version) ) {
390+
if ( ! version().equals(version) ) {
391391
this.changed = true;
392392
}
393393
return this.version = version;

0 commit comments

Comments
 (0)