Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jruby class loading bug (unable to load hadoop configuration class) #484

Closed
maddosz opened this issue Jan 7, 2013 · 2 comments
Closed

Comments

@maddosz
Copy link

maddosz commented Jan 7, 2013

My environment

java -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
jruby -v
jruby 1.7.2 (1.9.3p327) 2013-01-04 302c706 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_10-b18 [darwin-x86_64]

The Bug and how to reproduce it

I encounter a "java.lang.ClassNotFoundException" when calling a simple java class.
Checkout my repository https://github.com/maddosz/jruby_class_loading_bug to find everything you need. Executing the test.rb yields the following error

configuration.java:6:in `test': java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration
    from NativeMethodAccessorImpl.java:-2:in `invoke0'
    from NativeMethodAccessorImpl.java:57:in `invoke'
    from DelegatingMethodAccessorImpl.java:43:in `invoke'
    from Method.java:601:in `invoke'
    from JavaMethod.java:440:in `invokeDirectWithExceptionHandling'
    from JavaMethod.java:362:in `invokeStaticDirect'
    from StaticMethodInvoker.java:50:in `call'
    from CachingCallSite.java:306:in `cacheAndCall'
    from CachingCallSite.java:136:in `call'
    from test.rb:13:in `__file__'
    from test.rb:-1:in `load'
    from Ruby.java:810:in `runScript'
    from Ruby.java:803:in `runScript'
    from Ruby.java:674:in `runNormally'
    from Ruby.java:523:in `runFromMain'
    from Main.java:390:in `doRunFromMain'
    from Main.java:279:in `internalRun'
    from Main.java:221:in `run'
    from Main.java:201:in `main'
Caused by:
URLClassLoader.java:366:in `run': java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration
    from URLClassLoader.java:355:in `run'
    from AccessController.java:-2:in `doPrivileged'
    from URLClassLoader.java:354:in `findClass'
    from ClassLoader.java:423:in `loadClass'
    from Launcher.java:308:in `loadClass'
    from ClassLoader.java:356:in `loadClass'
    from configuration.java:6:in `test'
    from NativeMethodAccessorImpl.java:-2:in `invoke0'
    from NativeMethodAccessorImpl.java:57:in `invoke'
    from DelegatingMethodAccessorImpl.java:43:in `invoke'
    from Method.java:601:in `invoke'
    from JavaMethod.java:440:in `invokeDirectWithExceptionHandling'
    from JavaMethod.java:362:in `invokeStaticDirect'
    from StaticMethodInvoker.java:50:in `call'
    from CachingCallSite.java:306:in `cacheAndCall'
    from CachingCallSite.java:136:in `call'
    from test.rb:13:in `__file__'
    from test.rb:-1:in `load'
    from Ruby.java:810:in `runScript'
    from Ruby.java:803:in `runScript'
    from Ruby.java:674:in `runNormally'
    from Ruby.java:523:in `runFromMain'
    from Main.java:390:in `doRunFromMain'
    from Main.java:279:in `internalRun'
    from Main.java:221:in `run'
    from Main.java:201:in `main'

Any suggestions?

@mkristian
Copy link
Member

diff --git a/test.rb b/test.rb
index c74ddc0..ce08f85 100644
--- a/test.rb
+++ b/test.rb
@@ -6,10 +6,11 @@ require 'hadoop-core-1.0.3.jar'

the code below works

java_import 'org.apache.hadoop.conf.Configuration'

p Configuration.new

+p Configuration.new.class_loader

this does not work.

java_import 'ConfigurationApp'
+p ConfigurationApp.java_class.class_loader.to_s
ConfigurationApp.test

applying this patch reveals that ConfigurationApp.class is loaded by a
different classloader then Configuration.

I do no know why the ConfigurationApp is loaded in
sun.misc.Launcher$AppClassLoader and Configuration with the
Thread.currentThread.context_class_loader i.e. the JRubyClassLoader

I tried to put the ConfigurationApp into a jar and also into a package but
it gets always loaded by the AppClassLoader :(

maybe that sounds familiar to someone !

  • Kristian

On Mon, Jan 7, 2013 at 6:06 PM, maddosz notifications@github.com wrote:

My environment

java -version
java version "1.7.0_10"
Java(TM) SE Runtime Environment (build 1.7.0_10-b18)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)

jruby -v
jruby 1.7.2 (1.9.3p327) 2013-01-04 302c706 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_10-b18 [darwin-x86_64]

The Bug and how to reproduce it

I encounter a "java.lang.ClassNotFoundException" when calling a simple
java class.
Checkout my repository https://github.com/maddosz/jruby_class_loading_bugto find everything you need. Executing the test.rb yields the following
error

configuration.java:6:in test': java.lang.NoClassDefFoundError: org/apache/hadoop/conf/Configuration from NativeMethodAccessorImpl.java:-2:ininvoke0'
from NativeMethodAccessorImpl.java:57:in invoke' from DelegatingMethodAccessorImpl.java:43:ininvoke'
from Method.java:601:in invoke' from JavaMethod.java:440:ininvokeDirectWithExceptionHandling'
from JavaMethod.java:362:in invokeStaticDirect' from StaticMethodInvoker.java:50:incall'
from CachingCallSite.java:306:in cacheAndCall' from CachingCallSite.java:136:incall'
from test.rb:13:in __file__' from test.rb:-1:inload'
from Ruby.java:810:in runScript' from Ruby.java:803:inrunScript'
from Ruby.java:674:in runNormally' from Ruby.java:523:inrunFromMain'
from Main.java:390:in doRunFromMain' from Main.java:279:ininternalRun'
from Main.java:221:in run' from Main.java:201:inmain'
Caused by:
URLClassLoader.java:366:in run': java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration from URLClassLoader.java:355:inrun'
from AccessController.java:-2:in doPrivileged' from URLClassLoader.java:354:infindClass'
from ClassLoader.java:423:in loadClass' from Launcher.java:308:inloadClass'
from ClassLoader.java:356:in loadClass' from configuration.java:6:intest'
from NativeMethodAccessorImpl.java:-2:in invoke0' from NativeMethodAccessorImpl.java:57:ininvoke'
from DelegatingMethodAccessorImpl.java:43:in invoke' from Method.java:601:ininvoke'
from JavaMethod.java:440:in invokeDirectWithExceptionHandling' from JavaMethod.java:362:ininvokeStaticDirect'
from StaticMethodInvoker.java:50:in call' from CachingCallSite.java:306:incacheAndCall'
from CachingCallSite.java:136:in call' from test.rb:13:infile'
from test.rb:-1:in load' from Ruby.java:810:inrunScript'
from Ruby.java:803:in runScript' from Ruby.java:674:inrunNormally'
from Ruby.java:523:in runFromMain' from Main.java:390:indoRunFromMain'
from Main.java:279:in internalRun' from Main.java:221:inrun'
from Main.java:201:in `main'

Any suggestions?


Reply to this email directly or view it on GitHubhttps://github.com//issues/484.

@l1024
Copy link

l1024 commented Jan 7, 2013

if you remove the ConfigurationApp.class file from the working directory the solution with the jar file works fine (at least for me)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants