PicoContainer
  1. PicoContainer
  2. PICO-272

CachingComponentAdapter calls ObjectReference.get() twice

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2-RC2
    • Fix Version/s: 1.2
    • Component/s: PicoContainer (Java)
    • Labels:
      None
    • Number of attachments :
      0

      Description

      CachingComponentAdapter calls ObjectReference.get() twice when getting the component. The object reference may be expensive to create (thus it is cached).

      if (instanceReference.get() == null)

      { Object instance = super.getComponentInstance(container); instanceReference.set(instance); }

      return instanceReference.get()

      I also have had a problem with the second get() when using a 'NULL' cache (object reference that does not cache the value at all).

      I would like to change the above code to:

      Object instance = instanceReference.get();
      if (instance == null)

      { instance = super.getComponentInstance(container); instanceReference.set(instance); }

      return instance;

      Thanks,

      John.

        Activity

        Hide
        Jörg Schaible added a comment -

        Well, the idea is the ObjectReference to be the cache, so it should not be expensive to get the instance. And for the NullObjectReference ... why do you then use the CachingCA at all? ==> Continue discussion at the list please.

        Nevertheless, I've changed the code to call get() only once. Thanks for heads-up.

        Show
        Jörg Schaible added a comment - Well, the idea is the ObjectReference to be the cache, so it should not be expensive to get the instance. And for the NullObjectReference ... why do you then use the CachingCA at all? ==> Continue discussion at the list please. Nevertheless, I've changed the code to call get() only once. Thanks for heads-up.
        Jörg Schaible made changes -
        Field Original Value New Value
        Resolution Fixed [ 1 ]
        Fix Version/s 1.2 [ 11330 ]
        Assignee Joerg Schaible [ joehni ]
        Status Open [ 1 ] Closed [ 6 ]

          People

          • Assignee:
            Jörg Schaible
            Reporter:
            John Patterson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: