Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 21a9cbe3b8d5
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1512d9afe870
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Jul 24, 2015

  1. Define packages for classes in nested JARs

    Packages are defined in the private `defineClass(String name, Resource res)` of `URLClassLoader`, which is only called from `findClass(final String name)`. Thus, whenever `findClass()` in `URLClassLoader` throws `ClassNotFoundException` (e.g. for JARs within JARs), the package doesn't get defined, even if `findClass(String className)` in `JRubyClassLoader` is able to find and define the sought class. I've used http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/net/URLClassLoader.java for reference.
    Joel Segerlind committed Jul 24, 2015
    Copy the full SHA
    f77aea2 View commit details
  2. Add test for packages of classes in nested JARs

    The example would fail unless the package has been defined, as
    JavaClass#package would return nil, which obviously doesn't define the
    method #name.
    Joel Segerlind committed Jul 24, 2015
    Copy the full SHA
    c0a9e8e View commit details

Commits on Jul 25, 2015

  1. Merge pull request #3160 from jowl/define-package-in-nested-jars

    Define packages for classes in nested JARs
    kares committed Jul 25, 2015
    Copy the full SHA
    1512d9a View commit details
Showing with 26 additions and 0 deletions.
  1. +17 −0 core/src/main/java/org/jruby/util/JRubyClassLoader.java
  2. +9 −0 test/test_load.rb
17 changes: 17 additions & 0 deletions core/src/main/java/org/jruby/util/JRubyClassLoader.java
Original file line number Diff line number Diff line change
@@ -210,6 +210,11 @@ protected Class<?> findClass(String className) throws ClassNotFoundException {
}

byte[] data = output.toByteArray();
int dotIndex = className.lastIndexOf(".");
if (dotIndex != -1) {
String packageName = className.substring(0, dotIndex);
definePackageInternal(packageName);
}
return defineClass(className, data, 0, data.length);
} finally {
close(input);
@@ -329,4 +334,16 @@ private static void close(Closeable resource) {
}
}
}

private void definePackageInternal(String pkgname) {
if (getPackage(pkgname) == null) {
try {
definePackage(pkgname, null, null, null, null, null, null, null);
} catch (IllegalArgumentException iae) {
if (getPackage(pkgname) == null) {
throw new AssertionError("Cannot find package " + pkgname);
}
}
}
}
}
9 changes: 9 additions & 0 deletions test/test_load.rb
Original file line number Diff line number Diff line change
@@ -103,6 +103,15 @@ def test_require_nested_jar_enables_class_loading_from_that_jar
}
end

def test_require_nested_jar_defines_packages_for_classes_in_that_jar
assert_equal "test", run_in_sub_runtime(%{
require 'test/jar_with_nested_classes_jar'
require 'jar_with_classes'
java_import "test.HelloThere"
HelloThere.java_class.package.name
})
end

def call_extern_load_foo_bar(classpath = nil)
cmd = ""
cmd += "env CLASSPATH=#{classpath}" # classpath=nil, becomes empty CLASSPATH