Skip to content

Commit

Permalink
Reinstate "Avoid CNFE by setting classloader resource of service .cla…
Browse files Browse the repository at this point in the history
…ss."

This reverts commit 8794c47.
  • Loading branch information
headius committed Nov 25, 2014
1 parent d1f4d5b commit 35d5d13
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 35d5d13

Please sign in to comment.