Skip to content

Commit

Permalink
Import #1298
Browse files Browse the repository at this point in the history
Replace CGLIB with custom code to generate "enhancers" and "fast-classes".

Some user visible changes from using cglib:
- intercepted method that has a return type of int but returns null from the interceptor will no longer be automatically converted to 0, instead a NullPointerException will be thrown.
- Scope implementation can no longer check for circular proxy instance using CircularDependencyProxy marker class, instead should use Scopes.isCircularProxy
- Depending on which custom class loading option is used, Guice enhanced class may no longer be mockable/spyable
- Generated class name is slightly longer.

Closes #1298

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=320433559
  • Loading branch information
mcculls authored and kevinb9n committed Jul 9, 2020
1 parent 4e8a119 commit 2d867c5
Show file tree
Hide file tree
Showing 36 changed files with 2,965 additions and 683 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ javadoc.packagenames=com.google.inject,com.google.inject.spi,\
com.google.inject.testing.fieldbinder
test.class=com.google.inject.AllTests
module=com.google.inject
imports=!net.sf.cglib.*,!org.objectweb.asm.*
imports=!org.objectweb.asm.*
46 changes: 29 additions & 17 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@
<artifactId>guava</artifactId>
</dependency>
<!--
| CGLIB is embedded by default by the JarJar build profile
| ASM is embedded by default by the JarJar build profile
-->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<optional>true</optional>
</dependency>
<!--
| Test dependencies
-->
Expand Down Expand Up @@ -106,6 +101,31 @@
<exclude>**/TypeConversionTest*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>anonymous-class-loading</id>
<phase>test</phase>
<goals><goal>test</goal></goals>
<configuration>
<argLine>-Dguice_custom_class_loading=ANONYMOUS</argLine>
</configuration>
</execution>
<execution>
<id>child-class-loading</id>
<phase>test</phase>
<goals><goal>test</goal></goals>
<configuration>
<argLine>-Dguice_custom_class_loading=CHILD</argLine>
<!--
| These tests rely on package access which CHILD loading doesn't have
-->
<excludes combine.children="append">
<exclude>**/BytecodeGenTest*</exclude>
<exclude>**/ProviderMethodsTest*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<!--
| Add OSGi manifest
Expand All @@ -116,7 +136,7 @@
<configuration>
<instructions>
<Bundle-Name>${project.artifactId}$(if;$(classes;NAMED;*.MethodAspect);; (no_aop))</Bundle-Name>
<Import-Package>!net.sf.cglib.*,!org.objectweb.asm.*,!com.google.inject.*,*</Import-Package>
<Import-Package>!org.objectweb.asm.*,!com.google.inject.*,*</Import-Package>
<Eclipse-ExtensibleAPI>true</Eclipse-ExtensibleAPI>
</instructions>
</configuration>
Expand Down Expand Up @@ -180,6 +200,7 @@
<configuration>
<symbols>NO_AOP</symbols>
<excludes>
**/aop/*.java,
**/InterceptorBinding.java,
**/InterceptorBindingProcessor.java,
**/InterceptorStackCallback.java,
Expand Down Expand Up @@ -222,7 +243,7 @@
</profile>
<profile>
<!--
| JarJar build profile: Embed CGLIB (and ASM) classes under a Guice namespace
| JarJar build profile: Embed ASM classes under a Guice namespace
-->
<id>guice.with.jarjar</id>
<activation>
Expand All @@ -247,17 +268,8 @@
<overwrite>true</overwrite>
<includes>
<include>*:asm*</include>
<include>*:cglib</include>
</includes>
<rules>
<rule>
<pattern>net.sf.cglib.*</pattern>
<result>com.google.inject.internal.cglib.$@1</result>
</rule>
<rule>
<pattern>net.sf.cglib.**.*</pattern>
<result>com.google.inject.internal.cglib.@1.$@2</result>
</rule>
<rule>
<pattern>org.objectweb.asm.*</pattern>
<result>com.google.inject.internal.asm.$@1</result>
Expand Down
4 changes: 2 additions & 2 deletions core/src/com/google/inject/Scopes.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.google.inject;

import com.google.inject.internal.BindingImpl;
import com.google.inject.internal.CircularDependencyProxy;
import com.google.inject.internal.BytecodeGen;
import com.google.inject.internal.SingletonScope;
import com.google.inject.spi.BindingScopingVisitor;
import com.google.inject.spi.ExposedBinding;
Expand Down Expand Up @@ -197,6 +197,6 @@ private static Injector getInjector(LinkedKeyBinding<?> linkedKeyBinding) {
* @since 4.0
*/
public static boolean isCircularProxy(Object object) {
return object instanceof CircularDependencyProxy;
return BytecodeGen.isCircularProxy(object);
}
}
Loading

0 comments on commit 2d867c5

Please sign in to comment.