Strange intermittent Exception in thread "Thread-2" java.lang.NullPointerException error

Hello guys,

I am working in a multithreaded algorithm to perform some complex
searches on an Oracle database. For that I am using JDBC and
activerecord-jdbc-adapter (0.8.2).

The algorithm opens six different threads. Two of them use cursors to
select data from oracle. Both threads share the same connection, but
they have independent local cursors.

The algorithm works ok, but intermittently fails with a
NullPointerException. My problem is that I cannot identify what it is
producing the error. I cannot even identify which line in the code is
producing it because I cannot catch the transaction with rescue
Exception => error. The thread just aborts.

Any ideas? This is the complete error stack:

Exception in thread “Thread-2” java.lang.NullPointerException
at
org
.jruby.runtime.ThreadContext.getClassNameFromFrame(ThreadContext.java:
809)
at org.jruby.runtime.ThreadContext.buildTrace(ThreadContext.java:796)
at
org.jruby.runtime.ThreadContext.createBacktrace2(ThreadContext.java:790)
at
org.jruby.exceptions.RaiseException.setException(RaiseException.java:
145)
at org.jruby.exceptions.RaiseException.(RaiseException.java:69)
at org.jruby.Ruby.newRaiseException(Ruby.java:2723)
at org.jruby.Ruby.newTypeError(Ruby.java:2598)
at
org
.jruby
.javasupport.JavaMethod.invokeWithExceptionHandling(JavaMethod.java:301)
at org.jruby.javasupport.JavaMethod.invoke(JavaMethod.java:259)
at
org
.jruby
.java.invokers.InstanceMethodInvoker.call(InstanceMethodInvoker.java:44)
at org.jruby.runtime.CallSite
$InlineCachingCallSite.call(CallSite.java:391)
at
ruby.jit.ruby.usr.local.jruby_minus_1_dot_1_dot_4.lib.ruby.site_ruby.
$
1_dot_8
.builtin
.java
.collections._lt_equal_gt_15351875_2166653.file(collections.rb:20)
at
org
.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:
265)
at org.jruby.RubyClass.finvoke(RubyClass.java:362)
at
org.jruby.javasupport.util.RuntimeHelpers.invoke(RuntimeHelpers.java:
326)
at org.jruby.RubyObject.callMethod(RubyObject.java:732)
at org.jruby.RubyComparable.op_equal(RubyComparable.java:107)
at org.jruby.RubyComparable$s_method_1_0$RUBYINVOKER
$op_equal.call(org/jruby/RubyComparable$s_method_1_0$RUBYINVOKER
$op_equal.gen)
at org.jruby.runtime.CallSite
$InlineCachingCallSite.call(CallSite.java:391)
at search_engine.iqsearch.rescue_10$RUBY$rescue(iqsearch.rb:345)
at search_engine.iqsearch.method__39$RUBY
$search_leaf_thread(iqsearch.rb)
at search_engine.iqsearchInvokermethod__39$RUBY
$search_leaf_threadFixed0.call(search_engine/
iqsearchInvokermethod__39$RUBY$search_leaf_threadFixed0.gen)
at
org
.jruby
.internal.runtime.methods.CompiledMethod.call(CompiledMethod.java:216)
at org.jruby.runtime.CallSite
$InlineCachingCallSite.cacheAndCall(CallSite.java:132)
at org.jruby.runtime.CallSite
$InlineCachingCallSite.call(CallSite.java:343)
at search_engine.iqsearch.block_2$RUBY$block(iqsearch.rb:224)
at search_engine.iqsearchBlockCallback$block_2$RUBY
$__block__xx1.call(Unknown Source)
at org.jruby.runtime.CompiledBlock.yield(CompiledBlock.java:120)
at org.jruby.runtime.BlockBody.call(BlockBody.java:64)
at org.jruby.runtime.Block.call(Block.java:101)
at org.jruby.RubyProc.call(RubyProc.java:200)
at org.jruby.RubyProc.call(RubyProc.java:187)
at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:90)
at java.lang.Thread.run(Thread.java:613)

Thanks,

GA

Definitely warrants a bug report. This case should never happen. File a
bug and if you can provide a script or sample application that causes
the problem (even if it has to be run several times to cause it).
Reproducing it will help us resolve it very quickly.

Guillermo A. wrote:

The algorithm works ok, but intermittently fails with a
at org.jruby.runtime.ThreadContext.buildTrace(ThreadContext.java:796)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:391)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:391)
at
Thanks,

GA


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hello Charles,

the main problem to replicate this issue is that the thread that fails
is part of a quite big set of scripts that cannot work independently
and of course they cannot work without the database.

I can help you trying to isolate the problem to make it replicable,
but from the error stack itself I cannot find which line in the code
is causing the NullPointerException.

There are two suspicious things in the script:

  1. There is a “select” returning a field which is defined as
    “Number(10)” in Oracle. The number comes into the script as Java
    BigDecimal and I cannot convert it to bignum directly with “to_i”,
    since the method is not defined in this class. So I am calling
    “to_s.to_i”. Perhaps it could generate some kind of error inside with
    some particular values in the original field.

  2. When the values in the database are NULL, they are returned as 0
    instead of “nil”. So I am assuming that it will always comes as 0 and
    I also treat the field as numeric converting it with “to_s.to_i”. I
    could default the field as 0 instead of NULL directly. It would be the
    same for the code. What do you think?

Thanks,

GA

On Sep 20, 2008, at 1:19 AM, Charles Oliver N. wrote:

The algorithm opens six different threads. Two of them use cursors
org
at org.jruby.exceptions.RaiseException.(RaiseException.java:69)
.jruby
.java
326)
at search_engine.iqsearchInvokermethod__39$RUBY
$InlineCachingCallSite.call(CallSite.java:343)
Thanks,
GA


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hello guys,

I have found what the error was. I had the following lines in the
algorithm:

    bottom_node = 0
     bottom_node = row.getObject("bottom_node") if row.next
     if bottom_node != 0

The error was triggered by the last “if”. The reason was that
bottom_node allows NULL values in Oracle and it comes back as
java.math.BigDecimal data type to Ruby. If you try to compare a
BigDecimal with 0 in Java, it fails at compilation time because 0 is
not BigDecimal type. But in Ruby the result was the
NullPointerException. When the content returned in the field is
different than NULL and different than 0 it works ok.

So I have replaced it with the following code and now it runs ok:

    bottom_node = 0
     bottom_node = row.getObject("bottom_node").to_s.to_i if

row.next
if bottom_node != 0

The main problem is that there is no exception triggered. It fails
with the java error directly. Should this behavior reported as a bug?

Cheers,

GA