Imported Java class becomes NotFound during execution

Hello,

I don’t understand (and suspect a jruby bug) why my code fails midway
through identical iterations with a NativeException:
java.lang.ClassNotFoundException. The code repeats the same thing over
and over.
Code works fine if all is in one file, however it fails towards the 50th
iteration if it’s included from another file (which iteration exactly
changes each time, but so far in the range 48 to 56)

Details below. Am I doing something wrong? A known issue? Or is it a bug
that needs to be reported?

  • Case 1: jruby ./integration-test.rb -> All fine [Prints out

numbers from 1 to 100]

  • Case 2: jruby ./integration-test-2files.rb ->

NativeException: java.lang.ClassNotFoundException [Prints out numbers
from 1 to 52, then spews out a
java/lang/ClassLoader.java:373:in findClass': java.lang.ClassNotFoundException: com.xxx.yyy.zzz.ttt.GGClassName (NativeException) from java/lang/ClassLoader.java:321:inloadClass’
from java/lang/ClassLoader.java:266:in loadClass' from java/lang/Class.java:-2:inforName0’
from java/lang/Class.java:264:in forName' from java/io/ObjectInputStream.java:621:inresolveClass’
from java/io/ObjectInputStream.java:1592:in readNonProxyDesc' from java/io/ObjectInputStream.java:1513:inreadClassDesc’

The error message is slightly different with jruby 1.7.0RC2
LoadError: load error: integration-test –
java.lang.ClassNotFoundException: xxx.yyy.zzz.ttt.GGClassName
require at org/jruby/RubyKernel.java:1019


#./integration-test-2files.rb
require “java”
require ‘integration-test’


#./integration-test.rb
require “java”

module JavaRead
require ‘myjar.jar’
include_package ‘com.xxx.yyy.zzz.ttt’
end

def JavaRead::ReadStuff(file)
myin=
java.io.ObjectInputStream.new(java.io.BufferedInputStream.new(java.io.FileInputStream.new(java.io.File.new(file))))
begin
while obj= myin.readObject
end
rescue java.io.EOFException # Don’t know why Java is raising this one#
Likely strange input files
end
end

1.upto(100) {|i| JavaRead::ReadStuff(“import/12.dmp”) ; puts i}

Tested and reproduced with jruby

  • jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2011-10-27 6586) (OpenJDK
    64-Bit Server VM 1.6.0_24) [amd64-java]
  • jruby 1.6.8 (ruby-1.8.7-p357) (2012-09-18 1772b40) (OpenJDK 64-Bit
    Server VM 1.6.0_24) [linux-amd64-java]
  • jruby 1.7.0.RC2 (1.9.3p203) 2012-10-09 142cc7b on OpenJDK 64-Bit
    Server VM 1.6.0_24-b24 [linux-amd64]

on a Ubuntu Precise Pagolin

This email and any attachments are confidential, and may be legally
privileged and protected by copyright. If you are not the intended
recipient dissemination or copying of this email is prohibited. If you
have received this in error, please notify the sender by replying by
email and then delete the email completely from your system. Any views
or opinions are solely those of the sender. This communication is not
intended to form a binding contract unless expressly indicated to the
contrary and properly authorised. Any actions taken on the basis of this
email are at the recipient’s own risk.

Can you file an issue at bugs.jruby.org on this. The 50 times until
failure behavior is a clear issue we are doing something wrong when we
try and JIT the Ruby code in question.

If you run in interpreted (non-mixed) mode you should see this go away
(-X-C). That would only be a workaround since we like the JIT to work
:slight_smile:

-Tom

On Mon, Oct 15, 2012 at 1:14 AM, Andre Allavena
[email protected] wrote:

Details below. Am I doing something wrong? A known issue? Or is it a bug
java/lang/ClassLoader.java:373:in `findClass’:

require ‘integration-test’

jruby 1.6.8 (ruby-1.8.7-p357) (2012-09-18 1772b40) (OpenJDK 64-Bit Server VM
dissemination or copying of this email is prohibited. If you have received
this in error, please notify the sender by replying by email and then delete
the email completely from your system. Any views or opinions are solely
those of the sender. This communication is not intended to form a binding
contract unless expressly indicated to the contrary and properly authorised.
Any actions taken on the basis of this email are at the recipient’s own
risk.


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]

Created http://jira.codehaus.org/browse/JRUBY-6941 for this.

-X-C is doing the opposite of what I’m expecting:

  • jruby -X-C systematically fails, on both files [All 3 versions
    tested, error message varies, but always a ClassNotFound error]
  • jruby -X+C always works, on both files. [All 3 versions tested]

./jruby-1.6.8/bin/jruby -X-C integration-test.rb
NativeException: java.lang.ClassNotFoundException:
xxx/yyy/zzz/ttt/GGClassName
ReadStuff at integration-test.rb:13
(root) at integration-test.rb:21
upto at org/jruby/RubyInteger.java:135
(root) at integration-test.rb:21
[1] 373 exit 1 ./jruby-1.6.8/bin/jruby -X-C integration-test.rb

Could I be doing something stupid with the import?
While the jar files are in the current directory, I’m not doing anything
to the classpath (and not adding the current directory)

And why is -X-C crashing, [disable all compilation as per jruby -X]
and not -X+X [force compilation of all scripts before they are run
(except eval) as per jruby -X]

Thanks
Andr

Thomas E Enebo wrote on 15/10/12 16:17:

Can you file an issue at bugs.jruby.org on this. The 50 times until
failure behavior is a clear issue we are doing something wrong when we
try and JIT the Ruby code in question.

If you run in interpreted (non-mixed) mode you should see this go away
(-X-C). That would only be a workaround since we like the JIT to work
:slight_smile:

-Tom

On Mon, Oct 15, 2012 at 1:14 AM, Andre Allavena
[email protected]mailto:[email protected]
wrote:

Hello,

I don’t understand (and suspect a jruby bug) why my code fails midway
through identical iterations with a NativeException:
java.lang.ClassNotFoundException. The code repeats the same thing over
and
over.
Code works fine if all is in one file, however it fails towards the 50th
iteration if it’s included from another file (which iteration exactly
changes each time, but so far in the range 48 to 56)

Details below. Am I doing something wrong? A known issue? Or is it a bug
that needs to be reported?

Case 1: jruby ./integration-test.rb -> All fine [Prints out numbers

from
1 to 100]

Case 2: jruby ./integration-test-2files.rb ->

NativeException: java.lang.ClassNotFoundException [Prints out numbers
from
1 to 52, then spews out a
java/lang/ClassLoader.java:373:in findClass': java.lang.ClassNotFoundException: com.xxx.yyy.zzz.ttt.GGClassName (NativeException) from java/lang/ClassLoader.java:321:inloadClass’
from java/lang/ClassLoader.java:266:in loadClass' from java/lang/Class.java:-2:inforName0’
from java/lang/Class.java:264:in forName' from java/io/ObjectInputStream.java:621:inresolveClass’
from java/io/ObjectInputStream.java:1592:in readNonProxyDesc' from java/io/ObjectInputStream.java:1513:inreadClassDesc’

The error message is slightly different with jruby 1.7.0RC2
LoadError: load error: integration-test –
java.lang.ClassNotFoundException:
xxx.yyy.zzz.ttt.GGClassName
require at org/jruby/RubyKernel.java:1019


#./integration-test-2files.rb
require “java”
require ‘integration-test’


#./integration-test.rb
require “java”

module JavaRead
require ‘myjar.jar’
include_package ‘com.xxx.yyy.zzz.ttt’
end

def JavaRead::ReadStuff(file)
myin=
java.io.ObjectInputStream.new(java.io.BufferedInputStream.new(java.io.FileInputStream.new(java.io.File.new(file))))
begin
while obj= myin.readObject
end
rescue java.io.EOFException # Don’t know why Java is raising this one#
Likely strange input files
end
end

1.upto(100) {|i| JavaRead::ReadStuff(“import/12.dmp”) ; puts i}

Tested and reproduced with jruby

jruby 1.5.6 (ruby 1.8.7 patchlevel 249) (2011-10-27 6586) (OpenJDK
64-Bit
Server VM 1.6.0_24) [amd64-java]
jruby 1.6.8 (ruby-1.8.7-p357) (2012-09-18 1772b40) (OpenJDK 64-Bit
Server VM
1.6.0_24) [linux-amd64-java]
jruby 1.7.0.RC2 (1.9.3p203) 2012-10-09 142cc7b on OpenJDK 64-Bit Server
VM
1.6.0_24-b24 [linux-amd64]

on a Ubuntu Precise Pagolin

This email and any attachments are confidential, and may be legally
privileged and protected by copyright. If you are not the intended
recipient
dissemination or copying of this email is prohibited. If you have
received
this in error, please notify the sender by replying by email and then
delete
the email completely from your system. Any views or opinions are solely
those of the sender. This communication is not intended to form a
binding
contract unless expressly indicated to the contrary and properly
authorised.
Any actions taken on the basis of this email are at the recipient’s own
risk.


Andr Allavena, PhD
Consultant: Technology / Risk
+44 (0) 784 1211 552 (cell)
+61 (0) 7 3294 8763 [Before 1pm CET time due to the time difference with
Australia]

This email and any attachments are confidential, and may be legally
privileged and protected by copyright. If you are not the intended
recipient dissemination or copying of this email is prohibited. If you
have received this in error, please notify the sender by replying by
email and then delete the email completely from your system. Any views
or opinions are solely those of the sender. This communication is not
intended to form a binding contract unless expressly indicated to the
contrary and properly authorised. Any actions taken on the basis of this
email are at the recipient’s own risk.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs