Announcement Announcement Module
Collapse
No announcement yet.
ProxyFactoryBean duplicates interceptors on circular dependency Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ProxyFactoryBean duplicates interceptors on circular dependency

    There's a scenario in which a ProxyFactoryBean duplicates its interceptors, i.e. includes each one twice in the interceptors list (which results in each interceptor being executed twice on each call). This happens when one of the interceptors depends on the ProxyFactoryBean that it advises, and when the ProxyFactoryBean happens to be created before the interceptor.

    I know that this is a weird circular dependency scenario, but it would be nice Spring would either initialized the proxy instance properly or throw an exception in such cases; otherwise the fact that each interceptor applies twice can remain undetected.

    I've done a little debugging and it's pretty clear how this happens. ProxyFactoryBean.initializeAdvisorChain() gets called when the proxy is created. There is a flag (advisorChainInitialized) that indicates whether the advisor chain has already been initialized; this flag is checked at the beginning of the method and set after all the interceptors have been initialized. However, when one of the interceptors depends on the same ProxyFactoryBean, getObject() and initializeAdvisorChain() are called again on the same instance, and since the flag is not yet set, the interceptors are added to the list one more time.

    Could this qualify as a bug?

    Thanks,
    Lucian
Working...
X