PicoContainer
  1. PicoContainer
  2. PICO-191

Got it to throw new runtime exception: "Should never get here"

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Component/s: PicoContainer (Java)
    • Labels:
      None
    • Environment:
      Win2k, JSDK 1.4.1
    • Number of attachments :
      0

      Description

      I was messing around with PicoContainer and inadvertently got it to throw a new RuntimeException with the message, "Should never get here."
      Here are the two files:
      Bowl.java:
      import org.picocontainer.MutablePicoContainer;
      import org.picocontainer.defaults.DefaultPicoContainer;

      class Bowl
      {
      private final Fish[] fishes;
      private final Cod[] cods;
      public Bowl(Fish[] fishes, Cod[] cods)

      { this.fishes = fishes; this.cods = cods; }

      public Fish[] getFishes()

      { return fishes; }

      public Cod[] getCods()

      { return cods; }

      public static void main( String[] args )

      { MutablePicoContainer pico = new DefaultPicoContainer( ) ; pico.registerComponentImplementation(Shark.class); pico.registerComponentImplementation(Cod.class); pico.registerComponentImplementation(Bowl.class); Bowl bowl = (Bowl) pico.getComponentInstance(Bowl.class); Fish[] fishes = bowl.getFishes( ) ; for( int i = 0 ; i < fishes.length ; i++ ) System.out.println( "fish["+i+"]="+fishes[i] ) ; }

      }

      Fish.java:
      public interface Fish
      {
      }

      class Cod implements Fish
      {
      static int i = 0 ;
      int instanceNum ;
      public Cod( )

      { instanceNum = i++ ; } ;
      public String toString( ) { return "Cod #" + instanceNum ; }
      }

      class Shark implements Fish
      {
      static int i = 0 ;
      int instanceNum ;
      public Shark( ) { instanceNum = i++ ; }

      ;
      public String toString( )

      { return "Shark #" + instanceNum ; }

      }

      Here is the stack trace:
      java.lang.RuntimeException: Should never get here
      at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.instantiateComponent(ConstructorInjectionComponentAdapter.java:210)
      at org.picocontainer.defaults.InstantiatingComponentAdapter.getComponentInstance(InstantiatingComponentAdapter.java:45)
      at org.picocontainer.defaults.DecoratingComponentAdapter.getComponentInstance(DecoratingComponentAdapter.java:42)
      at org.picocontainer.defaults.CachingComponentAdapter.getComponentInstance(CachingComponentAdapter.java:37)
      at org.picocontainer.defaults.GenericCollectionComponentAdapter.getArrayInstance(GenericCollectionComponentAdapter.java:79)
      at org.picocontainer.defaults.GenericCollectionComponentAdapter.getComponentInstance(GenericCollectionComponentAdapter.java:66)
      at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getConstructorArguments(ConstructorInjectionComponentAdapter.java:220)
      at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.instantiateComponent(ConstructorInjectionComponentAdapter.java:195)
      at org.picocontainer.defaults.InstantiatingComponentAdapter.getComponentInstance(InstantiatingComponentAdapter.java:45)
      at org.picocontainer.defaults.DecoratingComponentAdapter.getComponentInstance(DecoratingComponentAdapter.java:42)
      at org.picocontainer.defaults.CachingComponentAdapter.getComponentInstance(CachingComponentAdapter.java:37)
      at org.picocontainer.defaults.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:297)
      at tutorial.Bowl.main(Bowl.java:31)
      Exception in thread "main"

      The IllegalAccessException caught in line 210 of ConstructorInjectionComponentAdapter is: java.lang.IllegalAccessException: Class org.picocontainer.defaults.ConstructorInjectionComponentAdapter can not access a member of class tutorial.Shark with modifiers "public"

      This is because Shark's constructor has package-level protection (despite what Java says about it being public) ant so it's not accessible to classes in the Pico packages. I guess there's nothing you can do about it, but it can definitely happen and Pico should watch out for it!

        Activity

        Aslak Hellesøy made changes -
        Field Original Value New Value
        Fix Version/s 1.0 [ 10423 ]
        Assignee Aslak Hellesoy [ rinkrank ]
        Hide
        Paul Hammant added a comment -

        I can't reproduce the bug as described. I've copied code into a TestCase, and it is not happening. See the try/catch fail().

        Daniel, can you catch up with the CVS version of Pico, and see if you can mod the test ( Issue0191TestCase.java ) to get the issue to happen as you describe.

        Show
        Paul Hammant added a comment - I can't reproduce the bug as described. I've copied code into a TestCase, and it is not happening. See the try/catch fail(). Daniel, can you catch up with the CVS version of Pico, and see if you can mod the test ( Issue0191TestCase.java ) to get the issue to happen as you describe.
        Hide
        Paul Hammant added a comment -

        It could be that JDK 1.4.2 as opposed to 1.4.1 is an issue.

        Show
        Paul Hammant added a comment - It could be that JDK 1.4.2 as opposed to 1.4.1 is an issue.
        Paul Hammant made changes -
        Fix Version/s 1.0.1 [ 10307 ]
        Fix Version/s 1.0 [ 10423 ]
        Hide
        Aslak Hellesøy added a comment -

        We can't reproduce this bug. We'll close this one in a week or so if we don't get any more feedback on this.

        Show
        Aslak Hellesøy added a comment - We can't reproduce this bug. We'll close this one in a week or so if we don't get any more feedback on this.
        Aslak Hellesøy made changes -
        Resolution Cannot Reproduce [ 5 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        Daniel Lipton added a comment -

        I was getting this bug with Java 1.4.2 as well as 1.4.1 when using picocontainer-1.0-RC1.jar. But when I downloaded everything through CVS and rebuilt, it worked fine. I guess the problem has been fixed.

        Show
        Daniel Lipton added a comment - I was getting this bug with Java 1.4.2 as well as 1.4.1 when using picocontainer-1.0-RC1.jar. But when I downloaded everything through CVS and rebuilt, it worked fine. I guess the problem has been fixed.
        Hide
        Jörg Schaible added a comment -

        What about the final release though?

        Show
        Jörg Schaible added a comment - What about the final release though?
        Hide
        Daniel Lipton added a comment -

        With the latest release (picocontainer-1.0.jar) it works fine. Here's the exception it spits out:
        org.picocontainer.PicoInitializationException
        at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.instantiateComponent(ConstructorInjectionComponentAdapter.java:212)
        at org.picocontainer.defaults.InstantiatingComponentAdapter.getComponentInstance(InstantiatingComponentAdapter.java:48)
        at org.picocontainer.defaults.DecoratingComponentAdapter.getComponentInstance(DecoratingComponentAdapter.java:42)
        at org.picocontainer.defaults.CachingComponentAdapter.getComponentInstance(CachingComponentAdapter.java:37)
        at org.picocontainer.defaults.GenericCollectionComponentAdapter.getArrayInstance(GenericCollectionComponentAdapter.java:79)
        at org.picocontainer.defaults.GenericCollectionComponentAdapter.getComponentInstance(GenericCollectionComponentAdapter.java:66)
        at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getConstructorArguments(ConstructorInjectionComponentAdapter.java:222)
        at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.instantiateComponent(ConstructorInjectionComponentAdapter.java:198)
        at org.picocontainer.defaults.InstantiatingComponentAdapter.getComponentInstance(InstantiatingComponentAdapter.java:48)
        at org.picocontainer.defaults.DecoratingComponentAdapter.getComponentInstance(DecoratingComponentAdapter.java:42)
        at org.picocontainer.defaults.CachingComponentAdapter.getComponentInstance(CachingComponentAdapter.java:37)
        at org.picocontainer.defaults.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:298)
        at tutorial.Bowl.main(Bowl.java:30)
        Caused by: java.lang.IllegalAccessException: Class org.picocontainer.defaults.InstantiatingComponentAdapter can not access a member of class tutorial.Shark with modifiers "public"
        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:268)
        at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:100)
        at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.instantiateComponent(ConstructorInjectionComponentAdapter.java:200)
        ... 12 more

        Show
        Daniel Lipton added a comment - With the latest release (picocontainer-1.0.jar) it works fine. Here's the exception it spits out: org.picocontainer.PicoInitializationException at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.instantiateComponent(ConstructorInjectionComponentAdapter.java:212) at org.picocontainer.defaults.InstantiatingComponentAdapter.getComponentInstance(InstantiatingComponentAdapter.java:48) at org.picocontainer.defaults.DecoratingComponentAdapter.getComponentInstance(DecoratingComponentAdapter.java:42) at org.picocontainer.defaults.CachingComponentAdapter.getComponentInstance(CachingComponentAdapter.java:37) at org.picocontainer.defaults.GenericCollectionComponentAdapter.getArrayInstance(GenericCollectionComponentAdapter.java:79) at org.picocontainer.defaults.GenericCollectionComponentAdapter.getComponentInstance(GenericCollectionComponentAdapter.java:66) at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getConstructorArguments(ConstructorInjectionComponentAdapter.java:222) at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.instantiateComponent(ConstructorInjectionComponentAdapter.java:198) at org.picocontainer.defaults.InstantiatingComponentAdapter.getComponentInstance(InstantiatingComponentAdapter.java:48) at org.picocontainer.defaults.DecoratingComponentAdapter.getComponentInstance(DecoratingComponentAdapter.java:42) at org.picocontainer.defaults.CachingComponentAdapter.getComponentInstance(CachingComponentAdapter.java:37) at org.picocontainer.defaults.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:298) at tutorial.Bowl.main(Bowl.java:30) Caused by: java.lang.IllegalAccessException: Class org.picocontainer.defaults.InstantiatingComponentAdapter can not access a member of class tutorial.Shark with modifiers "public" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:57) at java.lang.reflect.Constructor.newInstance(Constructor.java:268) at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:100) at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.instantiateComponent(ConstructorInjectionComponentAdapter.java:200) ... 12 more
        Aslak Hellesøy made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Aslak Hellesøy
            Reporter:
            Daniel Lipton
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: