PicoContainer
  1. PicoContainer
  2. PICO-156

Possible class cast exception in LifeCycleContainerBuilder

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0-RC-1
    • Component/s: PicoContainer (Java)
    • Labels:
      None
    • Number of attachments :
      2

      Description

      In the buildContainer method of LifeCycleContainerBuilder the incomming parentContainer is casted to a MutablePicoContainer without checking the type.
      If a non PicoContainer instance is passed as a parent a ClassCastException occurs.

      A test should take place if the parent is a MutablePicoContainer to avoid this class cast exception.

      1. LifecycleContainerBuilder.java
        3 kB
        Maarten Grootendorst
      2. NonMutablePicoContainerContainerTestCase.java
        5 kB
        Maarten Grootendorst

        Activity

        Hide
        Paul Hammant added a comment -

        What should the Builder do? What should be thrown?

        Show
        Paul Hammant added a comment - What should the Builder do? What should be thrown?
        Hide
        Maarten Grootendorst added a comment -

        The parentContainerRef passed in using the ObjectReference is not necessary a MutablePicoContainer, a PicoContainer instance should be supported as well.

        In the current implementation the parent is casted to MutablePicoContainer without checking.
        This will causes the ClassCastException and will disable the option to use another PicoContainer than MutablePicoContainer.

        I've will attach a proposal for the fix and a testcase to illustrate my point.

        Show
        Maarten Grootendorst added a comment - The parentContainerRef passed in using the ObjectReference is not necessary a MutablePicoContainer, a PicoContainer instance should be supported as well. In the current implementation the parent is casted to MutablePicoContainer without checking. This will causes the ClassCastException and will disable the option to use another PicoContainer than MutablePicoContainer. I've will attach a proposal for the fix and a testcase to illustrate my point.
        Hide
        Maarten Grootendorst added a comment -

        Testcase

        Show
        Maarten Grootendorst added a comment - Testcase
        Maarten Grootendorst made changes -
        Field Original Value New Value
        Attachment NonMutablePicoContainerContainerTestCase.java [ 11630 ]
        Hide
        Maarten Grootendorst added a comment -

        Patched source

        Show
        Maarten Grootendorst added a comment - Patched source
        Maarten Grootendorst made changes -
        Attachment LifecycleContainerBuilder.java [ 11631 ]
        Hide
        Paul Hammant added a comment -

        OK, I understand now.

        Show
        Paul Hammant added a comment - OK, I understand now.
        Hide
        Aslak Hellesøy added a comment -

        Applied.

        For the future, please submit patches in unified diff format as described in http://docs.codehaus.org/display/PICO/How+To+Contribute

        Show
        Aslak Hellesøy added a comment - Applied. For the future, please submit patches in unified diff format as described in http://docs.codehaus.org/display/PICO/How+To+Contribute
        Aslak Hellesøy made changes -
        Assignee Aslak Hellesoy [ rinkrank ]
        Fix Version/s 1.0-RC-1 [ 10461 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]

          People

          • Assignee:
            Aslak Hellesøy
            Reporter:
            Maarten Grootendorst
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 1 hour
              1h
              Remaining:
              Remaining Estimate - 1 hour
              1h
              Logged:
              Time Spent - Not Specified
              Not Specified