2009/5/29 dg <gil...@gmail.com>

>
> I'm seeing some unexpected exceptions when running Guice 2.0 inside
> Tomcat.  I've tried to reproduce in a unit test but honestly I don't
> know enough about class loaders/loading to get it to break.
>
> I'm seeing two related types of exceptions. Things work when setting
> guice.custom.loader to false and for us that's an acceptable work-
> around.
>

Hi Darren,

If possible could you try the patched 2.0 jar over at:


http://code.google.com/p/peaberry/source/browse/trunk/lib/build/guice-2.0-customloader.jar

as this contains the patch for Issue 343 and I'd be interested to know if
this also solves
your particular issue, as it could be related (depending on your Tomcat
configuration)

If the problem still occurs with the patched build then please open a new
issue - some
sort of testcase would really help, doesn't have to be JUnit, even a Tomcat
based test
would help :) but otherwise attach logs, etc. - basically what you already
have here

The problem is the AOP proxy classes are being generated in a separate
classloader
and this is the cause of the visibility issues, as package-private types are
not visible
from other classloaders. Guice tries to detect this to avoid introducing the
separate
classloader, but this seems not to be happening in your example.

The patch for 343 might help depending which classloaders are involved as
it's more
conservative about using classloaders - but then again it may not if the
detection logic
is at fault.

So please try the patched build and let me know how it goes!

-- 
Cheers, Stuart

----
> All of the classes I'm working with have intercepted methods. (Warp
> @Transactional, if it matters)  Package-private classes normally have
> package-private intercepted methods, and public classes normally have
> public intercepted methods. Explanations are somewhat simplified below
> - I'm not sure how much or what details are important.
>
> ----
> The first exception is from a package-private constructor in a public
> class.  The guice-generated class can't access the constructor of the
> class it's extending.  A work-around for this is to declare the
> constructor 'protected' instead of package-private.
>
> public class SyncScheduleService { @Inject SyncScheduleService
> ( Dependencies ... ) }
>
> Caused by: java.lang.IllegalAccessError: tried to access method
> c.t.m.impl.SyncScheduleService.<init>(L<signature>)V
> from class c.t.m.impl.SyncScheduleService$$EnhancerByGuice$$3c601d19
>        at c.t.m.impl.SyncScheduleService$$EnhancerByGuice$$3c601d19.<init>
> (<generated>)
>        at c.t.m.impl.SyncScheduleService$$EnhancerByGuice$$3c601d19$
> $FastClassByGuice$$ecc2655.newInstance(<generated>)
>
> ----
> The second exception is injecting a package-private class *into* a
> public class.  Workaround is either to declare AddTask package-private
> or to declare SyncTask public.
>
> SyncTask { @Inject SyncTask( Dependencies... ); }
> public AddTask{ @Inject public AddTask( SyncTask s; ) }
>
> Caused by: java.lang.IllegalAccessError: tried to access class
> c.t.m.impl.SyncTask from class c.t.m.impl.AddTask$$EnhancerByGuice$
> $f0cfc69b$$FastClassByGuice$$9bd56636
>        at c.t.m.impl.AddTask$$EnhancerByGuice$$f0cfc69b$$FastClassByGuice$
> $9bd56636.newInstance(<generated>)
>        at
> com.google.inject.internal.cglib.reflect.FastConstructor.newInstance
> (FastConstructor.java:40)
>
> ---
> Here is usually where I try to speculate about the underlying problem,
> but I'm a little lost as to what could be going on with Tomcat's crazy
> custom classloaders -- or frankly what Guice could even do about it.
>
> All suggestions/commentary/pontification or just sympathy are welcome!
>
> Thanks,
> Darren.
>
> >

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

Reply via email to