Bug 467799

Summary: Inner aspect cannot add an inter-type method if there is a 'private-final' method with the same signature in the parent class.
Product: [Tools] AspectJ Reporter: Jiyong Park <jjongpark>
Component: CompilerAssignee: aspectj inbox <aspectj-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: jjongpark
Version: 1.8.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows NT   
Whiteboard:

Description Jiyong Park CLA 2015-05-21 01:55:05 EDT
Inter-type declaration does not work when the following conditions are ALL met:

1) an aspect is declared inside a class.
2) the aspect tries to add a method into its enclosing class.
3) the enclosing class is extending some other class.
4) the parent class has a method whose signature is same as the inter-type method to be added.
5) the method in the parent class has 'private final' attribute.

The problem does not happen when the aspect is not declared inside a class or the method in the parent is declared as 'private', not 'private final'. It seems that the AspectJ compiler prohibits declaring a method when it finds a final method with same signature in parent classes *regardless* of the method's access modifier. When the final method is declared as 'private', the 'final' keyword should not prevent declaring a method with the same signature.


Example:

public class Parent {
	private final void foo() { } // method with private final
	private void foo2() { } // method with just private
}

class Child extends Parent {
	static aspect  MethodWithSameName {
		private void Child.foo() { } // compile error
		private void Child.foo2() { } // ok
	}
}

Result:
Parent.java:9 [error] can't override final void Parent.foo()
private void Child.foo() { }
                   ^^