(ann) java.lang.Class.getAnnotation() cache conflicts with RedefineClasses()

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P3
    • 6
    • Affects Version/s: 6
    • Component/s: core-libs
    • b86
    • generic
    • generic

        java.lang.Class.getAnnotation() is currently implemented with a cache:

            public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
                if (annotationClass == null)
                    throw new NullPointerException();

                initAnnotationsIfNecessary();
                return (A) annotations.get(annotationClass);
            }

        <snip>

            private synchronized void initAnnotationsIfNecessary() {
                if (annotations != null)
                    return;
                declaredAnnotations = AnnotationParser.parseAnnotations(
                    getRawAnnotations(), getConstantPool(), this);
                Class<?> superClass = getSuperclass();
                if (superClass == null) {
                    annotations = declaredAnnotations;
                } else {
                    annotations = new HashMap<Class, Annotation>();
                    superClass.initAnnotationsIfNecessary();
                    for (Map.Entry<Class, Annotation> e : superClass.annotations.entrySet()) {
                        Class annotationClass = e.getKey();
                        if (AnnotationType.getInstance(annotationClass).isInherited())
                            annotations.put(annotationClass, e.getValue());
                    }
                    annotations.putAll(declaredAnnotations);
                }
            }

        This cache means that getRawAnnotations() is only called once
        which doesn't interact well with JVM/TI RedefineClasses(). If
        a set of annotations is modified by RedefineClasses(), then
        the VM will return the modified annotation (once 5002251 is
        fixed), but the Java layer will never present the modified
        annotations to the caller.

              Assignee:
              Scott Seligman (Inactive)
              Reporter:
              Daniel Daugherty
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: