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

AnnotationInvocationHandler.equals(Object) return true when apply to annotation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u31
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b124
    • CPU:
      x86
    • OS:
      other
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_31"
      Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      Consider this simple test program:

        import java.lang.annotation.*;
        import java.lang.reflect.*;
        
        public class AnnotationBug {
        
            @Retention(RetentionPolicy.RUNTIME)
            @interface MyAnnotation {
            }
        
            @MyAnnotation
            public static void main(String[] args) throws Exception {
                Method main = AnnotationBug.class.getMethod("main", String[].class);
                MyAnnotation annotation = main.getAnnotation(MyAnnotation.class);
                InvocationHandler handler = Proxy.getInvocationHandler(annotation);
                assert handler.equals(annotation) == false: "1";
                assert annotation.equals(handler) == false: "2";
            }
        }

      This run with '-ea' option:

        Exception in thread "main" java.lang.AssertionError: 2
                at AnnotationBug.main(AnnotationBug.java:16)
        vimshell: exit 1 "java -ea AnnotationBug"

      The cause is the following code.
      http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/file/c46daef6edb5/src/share/classes/sun/reflect/annotation/AnnotationInvocationHandler.java#l191

      The code in URL, == operator applied to 'this' instance, but it should apply to proxy that is argument in 'invoke' method.


      REPRODUCIBILITY :
      This bug can be reproduced always.

        Attachments

          Activity

            People

            Assignee:
            darcy Joe Darcy
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: