Issue Details (XML | Word | Printable)

Key: JRUBY-66
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Charles Oliver Nutter
Reporter: Tim Bray
Votes: 0
Watchers: 1
Operations

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

Ruby-based implemenations of Java interfaces must call super() if they define initialize

Created: 07/Aug/06 01:51 PM   Updated: 30/Apr/07 03:12 AM   Resolved: 04/Jan/07 03:10 PM
Return to search
Component/s: Java Integration
Affects Version/s: JRuby 0.9.0
Fix Version/s: JRuby 0.9.8

Time Tracking:
Not Specified

File Attachments: 1. File no_more_initialize (2 kB)
2. File u.rb (0.5 kB)

Environment: Latest Ubuntu, Java 1.5.0.06, latest JRuby


 Description  « Hide

If I inherit from javax.xml.namespace.NamespaceContext but the class has a constructor with an argument, trying to use an instance blows up.



Charles Oliver Nutter added a comment - 07/Aug/06 08:25 PM

This is a known issue when implementing an interface in Ruby and providing an initalizer for that implementation. In order to allow the JRuby-provided proxy code to initialize properly, Ruby-based implementations of Java interfaces should call super with no arguments. I do not like this requirement and I will modify this bug to point specifically toward fixing it.

At any rate, as a workaround replace:

class NSCT1 < NamespaceContext

  def initialize foo
    # doesn't need to do anything
  end
...

with:

class NSCT1 < NamespaceContext

  def initialize foo
    super()
    # doesn't need to do anything
  end
...

Charles Oliver Nutter added a comment - 07/Aug/06 08:37 PM

Renaming. Ruby implementations should (if possible) not need to call super() when they define an initialize. It is a frequent source of confusion. I have no suggestions at the moment on how this should be fixed.


Thomas E Enebo added a comment - 04/Jan/07 02:14 PM

My patch to fix this issue....


Thomas E Enebo added a comment - 04/Jan/07 03:10 PM

Committed in 2669. This has a minor tweak from attached patch in bug to allow arbitrary number of arguments in initialize.