Issue Details (XML | Word | Printable)

Key: PICO-191
Type: Bug Bug
Status: Closed Closed
Resolution: Cannot Reproduce
Priority: Minor Minor
Assignee: Aslak Hellesoy
Reporter: Daniel Lipton
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
PicoContainer

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

Created: 24/May/04 04:06 PM   Updated: 31/Aug/08 08:14 AM
Component/s: PicoContainer (Java)
Affects Version/s: 1.0
Fix Version/s: 1.1

Time Tracking:
Not Specified

Environment: Win2k, JSDK 1.4.1


 Description  « Hide
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!



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul Hammant added a comment - 04/Jun/04 10:15 PM
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.


Paul Hammant added a comment - 04/Jun/04 10:17 PM
It could be that JDK 1.4.2 as opposed to 1.4.1 is an issue.

Aslak Hellesoy added a comment - 08/Jun/04 05:38 AM
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.

Daniel Lipton added a comment - 10/Jun/04 04:24 PM
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.

Joerg Schaible added a comment - 10/Jun/04 05:11 PM
What about the final release though?

Daniel Lipton added a comment - 11/Jun/04 01:59 PM
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