diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/agent/builder/AgentBuilder.java b/byte-buddy-dep/src/main/java/net/bytebuddy/agent/builder/AgentBuilder.java index 4c079cbb6f3..cca45a8f61a 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/agent/builder/AgentBuilder.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/agent/builder/AgentBuilder.java @@ -511,11 +511,16 @@ interface Narrowable extends Matchable, Identified { interface Extendable extends AgentBuilder, Identified { /** + *

* Applies the specified transformation as a decorative transformation. For a decorative transformation, the supplied * transformer is prepended to any previous transformation that also matches the instrumented type, i.e. both transformations * are supplied. This procedure is repeated until a transformer is reached that matches the instrumented type but is not * defined as decorating after which no further transformations are considered. If all matching transformations are declared * as decorating, all matching transformers are applied. + *

+ *

+ * Note: A decorating transformer is applied after previously registered transformers. + *

* * @return A new instance of this agent builder with the specified transformation being applied as a decorator. */ @@ -4650,12 +4655,12 @@ public String toString() { interface Decoratable extends Resolution { /** - * Prepends the supplied transformer to this resolution. + * Appends the supplied transformer to this resolution. * - * @param transformer The transformer to prepend. - * @return A new resolution with the supplied transformer prepended. + * @param transformer The transformer to append to the transformer that is represented bz this instance. + * @return A new resolution with the supplied transformer appended to this transformer. */ - Resolution prepend(Transformer transformer); + Resolution append(Transformer transformer); } /** @@ -4898,15 +4903,15 @@ public Transformation.Resolution asDecoratorOf(Transformation.Resolution resolut @Override public Transformation.Resolution prepend(Decoratable resolution) { - return resolution.prepend(transformer); + return resolution.append(transformer); } @Override - public Transformation.Resolution prepend(Transformer transformer) { + public Transformation.Resolution append(Transformer transformer) { return new Resolution(typeDescription, classLoader, protectionDomain, - new Transformer.Compound(transformer, this.transformer), + new Transformer.Compound(this.transformer, transformer), decorator); } diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/agent/builder/AgentBuilderDefaultApplicationTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/agent/builder/AgentBuilderDefaultApplicationTest.java index 85548b8936d..d8e6f4d7652 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/agent/builder/AgentBuilderDefaultApplicationTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/agent/builder/AgentBuilderDefaultApplicationTest.java @@ -274,8 +274,8 @@ public void testDecoration() throws Exception { assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); ClassFileTransformer classFileTransformer = new AgentBuilder.Default() .with(binaryLocator) - .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()) - .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer()).asDecorator() + .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer()) + .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()).asDecorator() .installOnByteBuddyAgent(); try { Class type = classLoader.loadClass(Foo.class.getName()); @@ -291,8 +291,8 @@ public void testDecorationFallThrough() throws Exception { assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); ClassFileTransformer classFileTransformer = new AgentBuilder.Default() .with(binaryLocator) - .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()).asDecorator() .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer()).asDecorator() + .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()).asDecorator() .installOnByteBuddyAgent(); try { Class type = classLoader.loadClass(Foo.class.getName()); @@ -308,12 +308,12 @@ public void testDecorationBlocked() throws Exception { assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); ClassFileTransformer classFileTransformer = new AgentBuilder.Default() .with(binaryLocator) - .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()).asDecorator() - .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer()) + .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer()).asDecorator() + .type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()) .installOnByteBuddyAgent(); try { Class type = classLoader.loadClass(Foo.class.getName()); - assertThat(type.getDeclaredMethod(FOO).invoke(type.newInstance()), is((Object) (FOO + BAR))); + assertThat(type.getDeclaredMethod(FOO).invoke(type.newInstance()), is((Object) (FOO + QUX))); } finally { ByteBuddyAgent.getInstrumentation().removeTransformer(classFileTransformer); }