Skip to content
Permalink
Browse files
Reinstate "Avoid CNFE by setting classloader resource of service .cla…
…ss."

This reverts commit 8794c47.
  • Loading branch information
headius committed Nov 25, 2014
1 parent d1f4d5b commit 35d5d135daef2f7cd53ee44fee9b37133f0c7405
Showing 1 changed file with 11 additions and 3 deletions.
@@ -29,6 +29,8 @@

import org.jruby.Ruby;

import java.net.URL;

/**
* The ClassExtensionLibrary wraps a class which implements BasicLibraryService,
* and when asked to load the service, does a basicLoad of the BasicLibraryService.
@@ -62,10 +64,16 @@ static ClassExtensionLibrary tryFind(Ruby runtime, String searchName) {

// We don't want a package name beginning with dots, so we remove them
String className = finName.toString().replaceAll("^\\.*", "");
String classFile = className.replaceAll("\\.", "/") + ".class";

// quietly try to load the class, which must be reachable as a .class resource
URL resource = runtime.getJRubyClassLoader().getResource(classFile);
if (resource != null) {
Class theClass = runtime.getJavaSupport().loadJavaClass(className);
return new ClassExtensionLibrary(className + ".java", theClass);
}

// quietly try to load the class
Class theClass = runtime.getJavaSupport().loadJavaClass(className);
return new ClassExtensionLibrary(className + ".java", theClass);
return null;
} catch (ClassNotFoundException cnfe) {
if (runtime.isDebug()) cnfe.printStackTrace();

0 comments on commit 35d5d13

Please sign in to comment.