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.


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to