Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to not use the reflection API when encountering loaded t…
…ypes during a retransformation or redefinition of a type but rather to rely onto the type pool-generated description.
- Loading branch information
Showing
6 changed files
with
360 additions
and
29 deletions.
There are no files selected for viewing
218 changes: 194 additions & 24 deletions
218
byte-buddy-dep/src/main/java/net/bytebuddy/agent/builder/AgentBuilder.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...dy-dep/src/test/java/net/bytebuddy/agent/builder/AgentBuilderDescriptionStrategyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package net.bytebuddy.agent.builder; | ||
|
||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.dynamic.ClassFileLocator; | ||
import net.bytebuddy.pool.TypePool; | ||
import net.bytebuddy.test.utility.MockitoRule; | ||
import net.bytebuddy.test.utility.ObjectPropertyAssertion; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
import org.mockito.Mock; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class AgentBuilderDescriptionStrategyTest { | ||
|
||
@Rule | ||
public TestRule mockitoRule = new MockitoRule(this); | ||
|
||
@Mock | ||
private AgentBuilder.TypeLocator typeLocator; | ||
|
||
@Mock | ||
private TypePool typePool; | ||
|
||
@Mock | ||
private TypeDescription typeDescription; | ||
|
||
@Test | ||
public void testDescriptionHybridWithLoaded() throws Exception { | ||
ClassFileLocator classFileLocator = ClassFileLocator.ForClassLoader.of(Object.class.getClassLoader()); | ||
when(typeLocator.typePool(classFileLocator, Object.class.getClassLoader())).thenReturn(typePool); | ||
when(typePool.describe(Object.class.getName())).thenReturn(new TypePool.Resolution.Simple(typeDescription)); | ||
TypeDescription typeDescription = AgentBuilder.DescriptionStrategy.HYBRID.apply(Object.class.getName(), | ||
Object.class, | ||
typeLocator, | ||
Object.class.getClassLoader(), | ||
classFileLocator); | ||
assertThat(typeDescription, is(TypeDescription.OBJECT)); | ||
assertThat(typeDescription, instanceOf(TypeDescription.ForLoadedType.class)); | ||
} | ||
|
||
@Test | ||
public void testDescriptionHybridWithoutLoaded() throws Exception { | ||
ClassFileLocator classFileLocator = ClassFileLocator.ForClassLoader.of(Object.class.getClassLoader()); | ||
when(typeLocator.typePool(classFileLocator, Object.class.getClassLoader())).thenReturn(typePool); | ||
when(typePool.describe(Object.class.getName())).thenReturn(new TypePool.Resolution.Simple(typeDescription)); | ||
TypeDescription typeDescription = AgentBuilder.DescriptionStrategy.HYBRID.apply(Object.class.getName(), | ||
null, | ||
typeLocator, | ||
Object.class.getClassLoader(), | ||
classFileLocator); | ||
assertThat(typeDescription, is(this.typeDescription)); | ||
} | ||
|
||
@Test | ||
public void testDescriptionPoolOnly() throws Exception { | ||
ClassFileLocator classFileLocator = ClassFileLocator.ForClassLoader.of(Object.class.getClassLoader()); | ||
when(typeLocator.typePool(classFileLocator, Object.class.getClassLoader())).thenReturn(typePool); | ||
when(typePool.describe(Object.class.getName())).thenReturn(new TypePool.Resolution.Simple(typeDescription)); | ||
assertThat(AgentBuilder.DescriptionStrategy.POOL_ONLY.apply(Object.class.getName(), | ||
Object.class, | ||
typeLocator, | ||
Object.class.getClassLoader(), | ||
classFileLocator), is(typeDescription)); | ||
} | ||
|
||
@Test | ||
public void testLoadedDescriptionHybrid() throws Exception { | ||
assertThat(AgentBuilder.DescriptionStrategy.HYBRID.apply(Object.class, typeLocator), is(TypeDescription.OBJECT)); | ||
assertThat(AgentBuilder.DescriptionStrategy.HYBRID.apply(Object.class, typeLocator), instanceOf(TypeDescription.ForLoadedType.class)); | ||
} | ||
|
||
@Test | ||
public void testLoadedDescriptionPoolOnly() throws Exception { | ||
when(typeLocator.typePool(ClassFileLocator.ForClassLoader.of(Object.class.getClassLoader()), Object.class.getClassLoader())).thenReturn(typePool); | ||
when(typePool.describe(Object.class.getName())).thenReturn(new TypePool.Resolution.Simple(typeDescription)); | ||
assertThat(AgentBuilder.DescriptionStrategy.POOL_ONLY.apply(Object.class, typeLocator), is(typeDescription)); | ||
} | ||
|
||
@Test | ||
public void testObjectProperties() throws Exception { | ||
ObjectPropertyAssertion.of(AgentBuilder.DescriptionStrategy.class).apply(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters