title: How to apply, remove and re-apply the bytebuddy transformation?
body: <p>I'm trying to <code>apply, remove and re-apply</code> the bytebuddy transformation via the javaagent as the following code. The remove is worked properly via the <code>ResettableClassFileTransformer::reset</code>, but the re-apply is no worked.</p>
  
  <pre class="lang-java prettyprint-override"><code>// The target classes
  
  public @interface ToString {
  }
  
  public interface Greetable {
      String say(final String name);
  }
  
  @ToString
  public class Greeter implements Greetable {
       public String say(final String name) {
           return "Hello " + name;
       }
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>//note the some transform is from the example
  new AgentBuilder.Transformer() {
    @Override
    public DynamicType.Builder transform(DynamicType.Builder builder,
                                         TypeDescription     typeDescription,
                                         ClassLoader         classloader,
                                         JavaModule          module) {
      return builder.method(named("say"))
                    .intercept(FixedValue.value("transformed");
    }
  })
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>// The transformation
  public class MyProgram {
      public static void main(final String[] args) {
          ByteBuddyAgent.install();
          AgentBuilder bldr = new AgentBuilder.Default().
                                               with(AgentBuilder.Listener.
                                                        StreamWriting.
                                                        toSystemOut()).
                                               with(RedefinitionStrategy.
                                                       RETRANSFORMATION).
                                               disableClassFormatChanges().
                                               type(isSubTypeOf(
                                                         Greetable.class)).
                                               transform(&lt;some transform&gt;);
          ResettableClassFileTransformer resetter = 
                                            bldr.installOnByteBuddyAgent();
          Greetable g1 = new Greeter();
          System.out.println(g1.say("001"));
  
          //remove the transformation
          resetter.reset(ByteBuddyAgent.getInstrumentation(),
                         RedefinitionStrategy.RETRANSFORMATION);
          Greetable g2 = new Greeter();
          System.out.println(g2.say("002"));
  
          //re-apply the transformation
          bldr.installOn(ByteBuddyAgent.getInstrumentation());
          Greetable g3 = new Greeter();
          System.out.println(g3.say("003"));
  
      }
  }
  </code></pre>
  
  <p>The output is</p>
  
  
  
  <pre><code>TRANSFORM Greetable [sun.misc.Launcher$AppClassLoader@7ab2bfe1,
                       null,
                       loaded=true]
  TRANSFORM Greeter [sun.misc.Launcher$AppClassLoader@7ab2bfe1,
                     null,
                     loaded=true]
  transformed //note: the g1.say() is transformed.
  
  Hello 002         //note: the g2 is an orginal
  
  TRANSFORM Greetable [sun.misc.Launcher$AppClassLoader@7ab2bfe1,
                       null,
                       loaded=true]
  TRANSFORM Greeter [sun.misc.Launcher$AppClassLoader@7ab2bfe1,
                     null,
                     loaded=true]
  Hello 003         //note the re-apply has not worked.
  </code></pre>
  
  <p>Could you please help to advise how to achieve the re-apply?</p>
  
  <h3>EDIT1</h3>
  
  <p>I've updated the <code>byte-buddy</code> to version <code>1.6.11</code> and changed the <code>AgentBuilder.Transformer</code>. The result still same. The <code>g3.say()</code> is not transformed.</p>
  
  <p>My environment is </p>
  
  <pre><code>Windows 10 64Bits
  
  java version "1.8.0_60"
  Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
  Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
  </code></pre>
  
  <h3>EDIT2</h3>
  
  <p>I've changed the type matcher from interface</p>
  
  <pre class="lang-java prettyprint-override"><code>type(isSubTypeOf(Greetable.class))
  </code></pre>
  
  <p>to concrete class as</p>
  
  <pre class="lang-java prettyprint-override"><code>type(isSubTypeOf(Greeter.class))
  </code></pre>
  
  <p>The <code>g3.say()</code> is transformed propery. Is there any limitation on interface matching and transforming?</p>