2 Replies Latest reply: Oct 25, 2012 5:57 AM by RavagliVirgilio RSS

    Closing URLClassLoader seemingly discards runtime annotations

    RavagliVirgilio
      I'm working with JDK 1.7, on Windows 7.
      I created the class num.Complex, in Uti.jar; and created an annotation, Remark, too, with policy = RUNTIME.
      Then I added the annotation to Complex:
      @Remark(comment="doesn't matter")
      public class Complex....

      From another application:
      URL[] urls = { new URL("file:/C:/LibJar/Uti.jar") };
      URLClassLoader loader = new URLClassLoader(urls);
      Class cls = loader.loadClass("num.Complex");
      loader.close();

      ....reflection code to show constructors, methods and fields: it works fine....

      Annotation[] notes = cls.getAnnotations();

      at this very point, I find NO annotations at all.
      If I don't close the loader, I find the annotation.

      Is it correct ? why annotations are treated differently ?

      thanks in advance
      Virgilio