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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b86
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        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.

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: