Hi Anne,
I tracked the exception down to a binding for a system type (java.util.Random)
in the OPT4J codebase that requires a constructor proxy - Guice checks with
the BytecodeGen utility class to decide whether it needs a bridge classloader
and it decides it doesn't for a system type, as mentioned in the Guice wiki:
http://code.google.com/p/google-guice/wiki/ClassLoading
Unfortunately, the classloader then returned by BytecodeGen is not the Guice
classloader but the system classloader. Of course this does not have access
to the internal Guice AOP classes, and the injector blows up :(
I tried changing the OPT4J code to avoid the constructor proxy, but I couldn't
get round it without making major changes to the code, so you'll need to use
a patched version of Guice (at least until this is fixed in trunk)
A quick fix would be to remove the following check from BytecodeGen.java:
if (delegate == getSystemClassLoaderOrNull()) {
return delegate;
}
Which would then enable bridging for system types - another option would be
to return the Guice class loader at this point instead of the system classloader:
if (delegate == getSystemClassLoaderOrNull()) {
return GUICE_CLASS_LOADER;
}
Either of these would solve your problem, but they are not complete because
the Guice classloader won't have access to types in the system classloader
that don't reside in the "java" namespace (such as javax.* / org.omg.*) unless
of course you enabled OSGi bootdelegation for these packages...
I've coded up a solution that doesn't suffer from this and raised a Guice issue:
http://code.google.com/p/google-guice/issues/detail?id=343
You can download a patched version of Guice here:
http://code.google.com/p/peaberry/source/browse/trunk/lib/build/guice-customloader-20090303.jar
which avoids the AOP exception.
Not sure if this patch will make it into Guice 2 because it is in a critical piece
of code, and I don't want to put any undue pressure on Jesse who's already
done a lot of testing with the current code.
Are you ok using the patched build until this is fixed in an official release?