Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9627

Regression: scoped beans being cached too aggressively

    Details

    • Last commented by a User:
      true

      Description

      The bugfix SPR-9176 "Scoped-proxy memory leak w/ @Resource injection" leads to bean instances being cached too eagerly in CommonAnnotationBeanPostProcessor. Besides the (desired) caching of AOP scoped-proxies to prevent the memory leak the current code also caches custom scoped bean instances that should not be cached. This happens for example if client code uses AutowireCapableBeanFactory#autowireBean(Object) to inject dependencies (annotation-based) into a manually created bean. In this case no AOP proxies are involved but the cached instances are still used. The underlying scope is never consulted and can thus never signalize that a new instance is to be created and injected because the context of the scope (e.g. request, session) is different from the first call which resulted in the cached instance.

      I attached a Test-Case (JUnit 4 Test, requires JUnit and Spring to run). The test-case illustrates the breaking change:

      • Runs fine with Spring version 3.1.1 and older (tested with 3.0.5)
      • Fails with Spring version 3.1.2 and 3.2.M1
      • The defect was introduced in the bugfix for SPR-9176 in version 3.2.M1 with commit f779c199ea272cf61781e120b1ab2efc50de0cbb
      • The defect was back-ported to version 3.1.2 with SPR-9363

      I understand this calling pattern is not very common but nevertheless the affected API is public and our framework relies on this to provide service beans to instances of "visual" classes (a visual models a single page in a web application). This basically renders custom scoped beans (also being used heavily) unusable for us in releases > 3.1.1, thus my classification as "major".

      Best regards
      Samuel Bernet
      MSc ETH Software Engineering
      [email protected]

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                sam_bernet Samuel Bernet
                Last updater:
                Chris Beams
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  6 years, 18 weeks ago