Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6407335

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • 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.

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

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: