Skip to content

Commit

Permalink
adding a skip-ed test-case for callin abstract (Ruby impl) method in …
Browse files Browse the repository at this point in the history
…constructor

this seems non-fixable without introducing some ugly hacks as the constructor's
super is allways the first call to happen and when it's calling an abstract method
that ends up at the Java proxy it will fail with a NPE as the invocation __handler field won't be initialized!

issue has been (previously) reported as #2369
kares committed Aug 25, 2015
1 parent dad257b commit c2ee8d6
Showing 2 changed files with 38 additions and 7 deletions.
29 changes: 24 additions & 5 deletions test/org/jruby/test/Abstract.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
package org.jruby.test;

public abstract class Abstract {
public String call_protected() {
return protected_method();
}

abstract protected String protected_method();
}
public String result = null;

public Abstract() { super(); }

public Abstract(boolean callProtected) {
// NOTE: the leaking this anti-pattern :
if ( callProtected ) result = call_protected();
}

public Abstract(final String result) {
this(check(result));
//if ( this.result == null ) this.result = result;
}

private static boolean check(final String name) {
return name.replace('_', ' ').contains("call protected method");
}

public String call_protected() {
return protected_method();
}

protected abstract String protected_method() ;
}
16 changes: 14 additions & 2 deletions test/test_java_extension.rb
Original file line number Diff line number Diff line change
@@ -272,21 +272,33 @@ def test_ruby_block_with_args_as_interface
assert listing.size >= 0
end

class ExtendedClass < org.jruby.test.Abstract
class RubyConcrete < org.jruby.test.Abstract
def protected_method
"Ruby overrides java!"
end
end

def test_overriding_protected_method
a = ExtendedClass.new
a = RubyConcrete.new
begin
assert_equal "Ruby overrides java!", a.call_protected
rescue Exception => e
flunk "Exception raised: #{e}"
end
end

class CallAbstractInConstructor < org.jruby.test.Abstract
def initialize; super("call protected method in constructor!") end

def protected_method; "HELLO!" end
end

def test_calling_abstract_method_in_java_constructor
skip('this leaking in super constructor (calling Ruby implemented methods)')
a = CallAbstractInConstructor.new
assert_equal "HELLO!", a.result
end

def test_map_interface_to_array
hash = {"one"=>"two","three"=>"four"}
map = java.util.HashMap.new(hash)

0 comments on commit c2ee8d6

Please sign in to comment.