groovy

Groovy 1.5 no longer calls a category method when the first argument's type is a parent class of the object's class and that class contains the method being overriden.

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: 1.5, 1.5.1, 1.5.2, 1.5.3, 1.5.4
  • Fix Version/s: 1.5.5
  • Component/s: None
  • Labels:
    None
  • Environment:
    Windows/XP, Sun Java SE 1.6.0_04-b12
  • Testcase included:
    yes
  • Number of attachments :
    1

Description

Groovy 1.5 no longer calls a category method when the class being augmented (first argument of category method) is a parent class of the object's class and that class contains the method being overriden. For example, given the category method 'Number pow( final Number base, final int exp )', if an instance of BigDecimal or BigInteger is used then the category method is not called, the object's method is called directly. However, if a Number sub-class is used that does not contain a 'pow(int)' method, then the category method will be called.

In Groovy 1.0 the category method is used in both of these situations, which seems to be the desired behavior.

I've attached a zip file with an example category class and junit test, that demonstrates this issue.

Activity

Hide
blackdrag blackdrag added a comment -

In fact this is no bug in 1.5 but in 1.0, which has been fixed in 1.5. Any Class defining a method in a more special class than the category base "overwrites" the category. BigInteger defines a pow method that takes an int, you defined a pow method on Number, so the BigInteger method is "overwriting" the Number method. This is kind of a failsafe to ensure that you do not overwrite methods you did not intend to overwrite with a category. Your "workaround" is the correct way to making this working.

Show
blackdrag blackdrag added a comment - In fact this is no bug in 1.5 but in 1.0, which has been fixed in 1.5. Any Class defining a method in a more special class than the category base "overwrites" the category. BigInteger defines a pow method that takes an int, you defined a pow method on Number, so the BigInteger method is "overwriting" the Number method. This is kind of a failsafe to ensure that you do not overwrite methods you did not intend to overwrite with a category. Your "workaround" is the correct way to making this working.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: