History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-2748
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Charles Oliver Nutter
Reporter: Michael Bohn
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

Can't subclass a Java class that calls an abstract function in its constructor

Created: 03/Jul/08 11:20 AM   Updated: Yesterday 03:20 AM
Component/s: Java Integration
Affects Version/s: JRuby 1.1.2
Fix Version/s: JRuby 1.1.5

Time Tracking:
Not Specified

File Attachments: 1. GZip Archive jrubyBug.tar.gz (1 kb)

Issue Links:
Duplicate
 


 Description  « Hide
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


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Charles Oliver Nutter - 03/Jul/08 02:22 PM
Feel like doing a little more homework and providing a case that fails too? And you can put LEFTBRACEnoformatRIGHTBRACE around your code snippits to format them right.

Michael Bohn - 07/Jul/08 09:31 AM
Actually, the case I provided does fail. My additional homework involved copy-pasting the above code into the appropriate files only to run them and encounter the bug. Attached are the files I just created to ensure the bug still exists. Try running and analyzing the files I submitted and you should see the error.

Here is the output I get when I run the attached:
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 abstractSubclass.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 abstractSubclass.rb:40


Michael Bohn - 05/Aug/08 02:17 PM
This bug also exists in 1.1.3. Anyone know if there is a plan to fix it?

Charles Oliver Nutter - 25/Aug/08 06:41 PM
I'll try to look at this one, seems like it could be a simpler issue buried in the guts of JI.

Charles Oliver Nutter - 27/Aug/08 03:20 AM
Bumping...not going to make it in 1.1.4