google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

AssistedInject needs class load bridging under OSGi #337

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
AssistedInject implements the factory interfaces by building dynamic
proxies. Under OSGi this creates the same class loading problem as with the
proxies and interceptors that Guice itself generates. So we need the
classloader bridges implemented in com.google.inject.internal.BytecodeGen.
Luckily BytecodeGen is built more as a standalone utility and this makes it
dead simple to solve the problem. I am attaching a 2-liner patch that calls
BytecodeGen during proxy generation to obtain a bridge ClassLoader for the
new proxy.

This patch must be used with Stuart's fragments patch from issue #311 to
get a working assistedinject bundle.

Btw I tried to replace the java.lang.reflect.Proxy with the fancier
BytecodeGen.newEnhancer(). Here I hit a wall because AssistedInject is
build against both the guice-snapshot.jar that contains a JarJar-mangled
cglib and the cglib-snapshot.jar from lib\build. After some toying with the
ant scripts I gave up and settled for just BytecodeGen.getClassLoader().

Finally I propose that BytecodeGen eventually be moved to the spi package
so that all extensions that need to generate proxies can use it.

Original issue reported on code.google.com by Rinsvind@gmail.com on 15 Feb 2009 at 1:25

Attachments:

GoogleCodeExporter commented 9 years ago
I'd like to get this resolved in Guice 2.1 if possible.

Original comment by mccu...@gmail.com on 30 Mar 2009 at 10:59

GoogleCodeExporter commented 9 years ago
There's a minor conflict with the previous patch and trunk.  Attaching an 
updated patch.

Original comment by rwallace...@gmail.com on 16 Apr 2009 at 4:33

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 26 Apr 2009 at 9:31

GoogleCodeExporter commented 9 years ago
Will make sure this patch is up-to-date as part of my general OSGi cleanup for 
2.1

Original comment by mccu...@gmail.com on 31 Oct 2009 at 4:02

GoogleCodeExporter commented 9 years ago
Description
===========

This patch updates the newProxyInstance calls in AssistedInject to use the
classloader provided by the internal BytecodeGen utility class. The BytecodeGen 
class
returns a classloader based on the type being proxied that still works in
custom-classloading scenarios.

Original comment by mccu...@gmail.com on 4 May 2010 at 10:34

Attachments:

GoogleCodeExporter commented 9 years ago
NOTE: the patch assumes that the internal BytecodeGen class has been made public

Index: src/com/google/inject/internal/BytecodeGen.java
===================================================================
--- src/com/google/inject/internal/BytecodeGen.java     (revision 1157)
+++ src/com/google/inject/internal/BytecodeGen.java     (working copy)
@@ -55,7 +55,7 @@
  * @author mcculls@gmail.com (Stuart McCulloch)
  * @author jessewilson@google.com (Jesse Wilson)
  */
-final class BytecodeGen {
+public final class BytecodeGen {

   private static final Logger logger = Logger.getLogger(BytecodeGen.class.getName());

Original comment by mccu...@gmail.com on 4 May 2010 at 10:41

GoogleCodeExporter commented 9 years ago

Original comment by mccu...@gmail.com on 4 May 2010 at 11:27

GoogleCodeExporter commented 9 years ago
fixed in r1158.  thanks very much for the patch, Stuart!

Original comment by sberlin on 9 May 2010 at 12:52