You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found that while subclassing a Java class that calls an abstract function in its constructor will cause the initialization of the subclass in JRuby to throw an ArgumentError with message "Constructor invocation failed: null."
Here is my Java base class:
package com.allstontrading.logalyzer;
import java.util.List;
public abstract class AbstractTest {
protected String obj;
public AbstractTest() {
this("dog");
this.run();
}
public AbstractTest(String obj) {
this.obj = obj;
}
protected abstract List<String> myAbstractFunc();
public void run() {
if (this.myAbstractFunc() != null)
for (String string : this.myAbstractFunc())
System.out.println("Big " + this.obj + "s Eat: " + string);
else
System.out.println("OMG");
}
}
Here is my example JRuby script:
include Java
import 'com.allstontrading.logalyzer.AbstractTest'
import 'java.util.ArrayList'
class RubyTest < com.allstontrading.logalyzer.AbstractTest
def initialize()
super("Pink Elephant")
end
def myAbstractFunc()
list = ArrayList.new
list << "Cancerous Rocks"
list << "Candy Apples"
list << "Moldy Bread"
return list
end
end
puts "This test does NOT call an abstract function in the constructor."
test = RubyTest.new
test.run
class AnotherRubyTest < com.allstontrading.logalyzer.AbstractTest
def initialize()
super
end
def myAbstractFunc()
list = ArrayList.new
list << "Cancerous Rocks"
list << "Candy Apples"
list << "Moldy Bread"
return list
end
end
puts ""
puts ""
puts "This test does call an abstract function in the constructor."
anotherTest = AnotherRubyTest.new
Here is the output:
This test does NOT call an abstract function in the constructor.
Big Pink Elephants Eat: Cancerous Rocks
Big Pink Elephants Eat: Candy Apples
Big Pink Elephants Eat: Moldy Bread
This test does call an abstract function in the constructor.
/home/mbohn/jruby-1.1.2/lib/ruby/site_ruby/1.8/builtin/javasupport/utilities/base.rb:26:in `new_instance2': Constructor invocation failed: null (ArgumentError)
from /home/mbohn/jruby-1.1.2/lib/ruby/site_ruby/1.8/builtin/javasupport/utilities/base.rb:26:in `__jcreate!'
from /home/mbohn/jruby-1.1.2/lib/ruby/site_ruby/1.8/builtin/javasupport/proxy/concrete.rb:23:in `initialize'
from rubyTestAbstract.rb:26:in `initialize'
from /home/mbohn/jruby-1.1.2/lib/ruby/site_ruby/1.8/builtin/javasupport/proxy/concrete.rb:6:in `new'
from /home/mbohn/jruby-1.1.2/lib/ruby/site_ruby/1.8/builtin/javasupport/proxy/concrete.rb:6:in `new'
from rubyTestAbstract.rb:41
The text was updated successfully, but these errors were encountered:
…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
From http://jira.codehaus.org/browse/JRUBY-2748
Original report
I have found that while subclassing a Java class that calls an abstract function in its constructor will cause the initialization of the subclass in JRuby to throw an ArgumentError with message "Constructor invocation failed: null."
Here is my Java base class:
Here is my example JRuby script:
Here is the output:
The text was updated successfully, but these errors were encountered: