Aquarium icon indicating copy to clipboard operation
Aquarium copied to clipboard

[RubyForge-18325] Can't cleanly remove advice from Ruby classes that extend Java classes, when using `:types_and_descendents=>Java_type`

Open hedgehog opened this issue 15 years ago • 0 comments

Date:2008-02-23 21:21 Priority:4 Submitted By:Dean Wampler (deanwampler) Assigned To:Dean Wampler (deanwampler) Category:JRuby Integration State:Open Summary:Can't cleanly remove advice from Ruby classes that extend Java classes, when using :types_and_descendents=>Java_type

Detailed description

Consider a Java class Base and a Ruby class Derived that subclasses Base:

package com.foo;
public class Base {
  public void doit() {}
}

class Derived < Java::ComFoo::Base
end

Then apply an aspect like

my_aspect = aspect :before, :types_and_descendents => Base, :calls_to => :doit do; ...; end

Then call my_aspect.unadvise later, Aquarium does not properly clean up the advice infrastructure from Derived which it creates for the doit method (even though doit isn't defined in Derived).

It appears to work fine if you advise a Java hierarchy only or you advise the Ruby class and only the methods it explicitly defines, including overrides of Java-class methods. The following changes to my_aspect work fine.

my_aspect = aspect :before, :types => Base, :calls_to => :doit do; 
... 
end
my_aspect = aspect :before, :types_and_descendents => Base, :calls_to => :doit, :restrict_methods_to => exclude_ancestor_methods do
 ...
end

The 2nd variation works because doit is only defined in Base, so only that version will be advised.

hedgehog avatar Jan 28 '10 23:01 hedgehog