Skip to content

Commit

Permalink
Fix JRUBY-6324: `pollAndGetClass': java.lang.NullPointerException
Browse files Browse the repository at this point in the history
The problem here was that srand's global seed was not initialized
at boot, resulting in the first call returning null. That null
propagated into Ruby execution, eventually blowing up in a call
site.

My fix is to make an initial call to the srand logic, creating a
first seed.
  • Loading branch information
headius committed Jan 7, 2012
1 parent 2bbaa3c commit 0bd3bd0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/org/jruby/Ruby.java
Expand Up @@ -1179,10 +1179,6 @@ private void initCore() {

encodingService = new EncodingService(this);

if (is1_9()) {
RubyRandom.createRandomClass(this);
}

RubySymbol.createSymbolClass(this);

if (profile.allowClass("ThreadGroup")) {
Expand Down Expand Up @@ -1300,6 +1296,10 @@ private void initCore() {
if (profile.allowClass("Continuation")) {
RubyContinuation.createContinuation(this);
}

if (is1_9()) {
RubyRandom.createRandomClass(this);
}
}

public static final int NIL_PREFILLED_ARRAY_SIZE = RubyArray.ARRAY_DEFAULT_SIZE * 8;
Expand Down
4 changes: 4 additions & 0 deletions src/org/jruby/RubyRandom.java
Expand Up @@ -56,6 +56,10 @@ public static RubyClass createRandomClass(Ruby runtime) {
runtime.setRandomClass(randomClass);

randomClass.defineAnnotatedMethods(RubyRandom.class);

// initialize the global seed by triggering an iteration
srandCommon(runtime.getCurrentContext(), randomClass, runtime.getNil(), false);

return randomClass;
}

Expand Down

0 comments on commit 0bd3bd0

Please sign in to comment.