Skip to content

Commit f4ff889

Browse files
committed
avoid regression in loading Java classes with upper case package names (fixes #2742)
... caused by the internal cleanup (the regression is not part of any 1.7.x release) one can only test this with *-Xji.upper.case.package.name.allowed=true* but since there's another failure the feature introduces, this will need to be revisited
1 parent 052e0d0 commit f4ff889

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

core/src/main/java/org/jruby/javasupport/Java.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,13 @@ private static RubyModule getProxyOrPackageUnderPackage(final ThreadContext cont
943943
// we'll try as a package
944944
result = getJavaPackageModule(runtime, fullName);
945945
// NOTE result = getPackageModule(runtime, name);
946+
if ( result == null ) {
947+
throw runtime.newNameError("missing class (or package) name (`" + fullName + "')", fullName);
948+
}
949+
}
950+
else {
951+
throw runtime.newNameError("missing class name (`" + fullName + "')", fullName);
946952
}
947-
throw runtime.newNameError("missing class name (`" + fullName + "')", fullName);
948953
}
949954
}
950955
catch (RuntimeException e) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.jruby.javasupport.TestApp;
2+
3+
public abstract class UpperClass {
4+
public static Object UglyMethod() { return "UGLY!"; }
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.jruby.javasupport.TestApp;
2+
3+
public class lowerClass {
4+
public static String UglyMethod() { return "ugly!"; }
5+
}

test/test_higher_javasupport.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class TestHigherJavasupport < Test::Unit::TestCase
1313
Annotation = java.lang.annotation.Annotation
1414
ClassWithPrimitive = org.jruby.test.ClassWithPrimitive
1515

16+
ALLOW_UPPERCASE_PACKAGE_NAMES = JRuby.runtime.getInstanceConfig.getAllowUppercasePackageNames
17+
1618
def test_java_int_primitive_assignment
1719
assert_nothing_raised {
1820
cwp = ClassWithPrimitive.new
@@ -447,8 +449,10 @@ def test_expected_missing_interface_method
447449
end
448450

449451
def test_that_misspelt_fq_class_names_dont_stop_future_fq_class_names_with_same_inner_most_package
452+
# NOTE: with ALLOW_UPPERCASE_PACKAGE_NAMES this raises nothing !
450453
assert_raises(NameError) { Java::java.til.zip.ZipFile }
451-
assert_nothing_raised { Java::java.util.zip.ZipFile }
454+
Java::java.util.zip.ZipFile
455+
Java::java.util.zip.ZipFile::OPEN_READ
452456
end
453457

454458
def test_that_subpackages_havent_leaked_into_other_packages
@@ -465,6 +469,19 @@ def test_that_we_get_the_same_package_instance_on_subsequent_calls
465469
assert(com.flirble.equal?(com.flirble))
466470
end
467471

472+
def test_uppercase_package_name_and_lowercase_class_name # and upper-case method
473+
Java::org.jruby.javasupport.TestApp
474+
Java::org.jruby.javasupport.TestApp.UpperClass
475+
assert_equal 'UGLY!', Java::org.jruby.javasupport.TestApp::UpperClass.UglyMethod
476+
477+
Java::org.jruby.javasupport.TestApp::lowerClass
478+
assert_equal 'ugly!', Java::org.jruby.javasupport.TestApp.lowerClass.UglyMethod
479+
480+
# NOTE: can not work due package case conventions :
481+
# Java::OrgJrubyJavasupportTestApp::UpperClass
482+
# Java::OrgJrubyJavasupportTestApp::lowerClass
483+
end if ALLOW_UPPERCASE_PACKAGE_NAMES
484+
468485
@@include_proc = Proc.new do
469486
Thread.stop
470487
java_import "java.lang.System"

0 commit comments

Comments
 (0)