PicoContainer
  1. PicoContainer
  2. PICO-342

Generics regression in Pico2.4 + (Tim Cleaver)

    Details

    • Type: Bug Bug
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4
    • Fix Version/s: 2.8
    • Component/s: None
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      /*****************************************************************************
       * Copyright (C) PicoContainer Organization. All rights reserved.            *
       * ------------------------------------------------------------------------- *
       * The software in this package is published under the terms of the BSD      *
       * style license a copy of which has been included with this distribution in *
       * the LICENSE.txt file.                                                     *
       *                                                                           *
       * Original code by                                                          *
       *****************************************************************************/
      package org.picocontainer.defaults.issues;
      
      import static org.junit.Assert.fail;
      import static org.junit.Assert.assertNotNull;
      
      import org.junit.Test;
      import org.junit.Assert;
      import org.picocontainer.DefaultPicoContainer;
      import org.picocontainer.MutablePicoContainer;
      import org.picocontainer.injectors.AbstractInjector;
      
      public final class IssueXxxxTestCase {
      
          interface Interface {
          }
      
          interface SubInterface extends Interface {
          }
      
          public static class Generic<I extends Interface> {
              private final I iface;
      
              public Generic(final I iface) {
                  this.iface = iface;
              }
          }
      
          public static class Implementation implements Interface {
          }
      
          public static class SubImplementation implements SubInterface {
          }
      
      
          @Test
          public void testNotTheBug() {
              //hard coded instantitation
              Generic<Implementation> generic1 = new Generic<Implementation>(new Implementation());
              Assert.assertNotNull(generic1);
              Generic<SubImplementation> generic2 = new Generic<SubImplementation>(new SubImplementation());
              Assert.assertNotNull(generic2);
          }
      
      
          @Test
          public void testTheBug() {
      
              //using picocontainer
              DefaultPicoContainer container = new DefaultPicoContainer();
              container.addComponent(Implementation.class);
              container.addComponent(Generic.class);
              Generic result = container.getComponent(Generic.class); // fails here.
              Assert.assertNotNull(result);
              Assert.assertNotNull(result.iface);
      
          }
      
      
          @Test
          public void testTheBug2() {
      
              DefaultPicoContainer container = new DefaultPicoContainer();
              container.addComponent(SubImplementation.class);
              container.addComponent(Generic.class);
              //should be Generic<SubImplementation> but requires unsafe cast
              Generic<SubImplementation> result2 = container.getComponent(Generic.class); // fails here
              Assert.assertNotNull(result2);
              Assert.assertNotNull(result2.iface);
      
          }
      
      }
      
      

        People

        • Assignee:
          Paul Hammant
          Reporter:
          Paul Hammant
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated: