That explains it, Max!  Perhaps AssistedInject should fail-fast when it
detects a public Factory being used with a non-public implementation?

Sam

On Mon, Sep 21, 2009 at 5:19 PM, Max Bowsher <[email protected]> wrote:

> Sam Berlin wrote:
> > I have a situation where we have a class with a factory provided by
> > AssistedInject.  The class is package private, and the factory is an
> > interface defined in the class.  For example:
> >
> >    class FooImpl implements Foo {
> >        static interface Factory {
> >            FooImpl create(@Assisted Param param);
> >        }
> >    }
> >
> > The impl has the factory because the user of it is in the same package &
> > needs the specifics of the implementation, not the interface.  What is
> > incredibly strange is that if I made the factory public, ie: "public
> > static interface Factory", then I receive the following exception when
> > calling create on the assisted-inject-created Factory:
> >   java.lang.IllegalAccessError: tried to access class FooImpl from class
> > $Proxy44 at $Proxy44.create(Unknown Source)
> >
> > If I remove the "public" modifier (so the interface is considered
> > package-private), the exception goes away & things work swimmingly.
> >
> > Anyone have any ideas about this?  It seems more related to the way
> > Proxy works than with AssistedInject, but I figured I'd open the floor..
>
> These two sentences from the javadoc of java.lang.reflect.Proxy are the
> key, I think:
>
> "If a proxy class implements a non-public interface, then it will be
> defined in the same package as that interface. Otherwise, the package of
> a proxy class is also unspecified."
>
> Max.
>
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to