I want to use ASM bytecode manipulation to add an Annotation to a foreign class, but it seems that I am missing something. The printed result is still without any annotation.
private void fixAnnotations4Classes() throws Exception {
final ClassReader reader = new ClassReader("some/3rdparty/class/Foo");
final ClassNode classNode = new ClassNode();
reader.accept(classNode, 0);
List<FieldNode> fields = classNode.fields;
List<AnnotationNode> visibleAnnotations = fields.get(0).visibleAnnotations;
visibleAnnotations.add(new AnnotationNode("my/new/Annotation"));
ClassWriter writer = new ClassWriter(0);
classNode.accept(writer);
System.out.println(Arrays.toString(Foo.class.getDeclaredField("profile").getAnnotations()));
System.out.println("FIN");
}