title: Add annotation to type at runtime using javassist
body: <p>I have the following code for the dynamic addition of annotation to java class</p>
  
  <pre><code>private void decorateWithSpecificAnnotation(final Set&lt;Class&lt;?&gt;&gt; domainClasses) {
      final ClassPool cp = ClassPool.getDefault();
      for (Class&lt;?&gt; c : domainClasses) {
          try {
              final CtClass cc = cp.get(c.getName());
              final ClassFile cfile = cc.getClassFile();
              final ConstPool cpool = cfile.getConstPool();
              final AnnotationsAttribute attr = new AnnotationsAttribute(cc.getClassFile().getConstPool(), AnnotationsAttribute.visibleTag);
              final Annotation annot = new Annotation(Document.class.getName(), cpool);
              attr.addAnnotation(annot);
              cfile.addAttribute(attr);
          } catch (NotFoundException e) {
              throw new RuntimeException("Unexpected error occured during dynamic domain decoration", e);
          }
      }
  }
  </code></pre>
  
  <p>After calling the above method when I do the following i see that annotation is not present. What i am missing.</p>
  
  <pre><code>decorateWithSpecificAnnotation(domainClasses);
  domainClasses.stream().forEach(d -&gt; {
      System.out.println(d.isAnnotationPresent(Document.class));
  });
  </code></pre>