Details
-
Type: Bug
-
Status: Closed
-
Priority: 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 :
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)
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( )
public String toString( ) { return "Cod #" + instanceNum ; }
}
class Shark implements Fish
{
static int i = 0 ;
int instanceNum ;
public Shark( ) { instanceNum = i++ ; }
;
public String toString( )
}
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
Field | Original Value | New Value |
---|---|---|
Fix Version/s | 1.0 [ 10423 ] | |
Assignee | Aslak Hellesoy [ rinkrank ] |
Fix Version/s | 1.0.1 [ 10307 ] | |
Fix Version/s | 1.0 [ 10423 ] |
Resolution | Cannot Reproduce [ 5 ] | |
Status | Open [ 1 ] | Resolved [ 5 ] |
Status | Resolved [ 5 ] | Closed [ 6 ] |
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.