JRuby

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

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: JRuby 0.9.0
  • Fix Version/s: JRuby 0.9.8
  • Component/s: Java Integration
  • Labels:
    None
  • Environment:
    Latest Ubuntu, Java 1.5.0.06, latest JRuby
  • Number of attachments :
    2

Description

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

  1. no_more_initialize
    04/Jan/07 2:14 PM
    2 kB
    Thomas E Enebo
  2. u.rb
    07/Aug/06 1:51 PM
    0.5 kB
    Tim Bray

Activity

Hide
Charles Oliver Nutter added a comment -

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
...
Show
Charles Oliver Nutter added a comment - 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
...
Hide
Charles Oliver Nutter added a comment -

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.

Show
Charles Oliver Nutter added a comment - 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.
Hide
Thomas E Enebo added a comment -

My patch to fix this issue....

Show
Thomas E Enebo added a comment - My patch to fix this issue....
Hide
Thomas E Enebo added a comment -

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

Show
Thomas E Enebo added a comment - Committed in 2669. This has a minor tweak from attached patch in bug to allow arbitrary number of arguments in initialize.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: