Hi,
I have an interface:
Code:
public interface MyInterface {
void doA();
void doB();
}
which has an abstract implementation
Code:
public abstract AbstractImpl {
public final void doA() {
// method implementation omitted
}
}
In the real code, doA() is fully implemented, and therefore marked final. The concrete implementation of this class is:
Code:
public class ConcreteImpl extends AbstractImpl {
Object dependency;
@Resource(name = "dependency")
void setDependency(Object obj) {
dependency = obj;
}
@Transactional(propagation = Propagation.REQUIRED)
void doB() {
dependency.toString();
}
}
At runtime a NullPointerException is thrown when doB() is called. Apparently what happens is:
- A transactional proxy is created by CGLIB for ConcreteImpl
- setDependency() is called on the target
- When doB() is called on the proxy, dependency is null, which causes the NPE
However if I remove the final modifier from doA() in AbstractImpl everything works fine. I guess the proxy is created via inheritance, and uses method overriding, which obviously won't work if a method is declared final. However, given that I really don't want subclasses to override doA() I'm not happy about removing the final modifier - any suggestions?
Thanks in advance,
DM