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

Potential data race in java.lang.reflect.ProxyGenerator.addProxyMethod related to ProxyGenerator.hashCodeMethod

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 23
    • 21
    • core-libs

      We are seeing data race reported by tsan in java.lang.reflect.ProxyGenerator.addProxyMethod(). I did some analysis of the tsan report. It appears there are two different threads read/write a shared (same) ProxyMethod concurrently, while processing two different annotations. One thread is reading a ProxyMethod.exceptionTypes and the other thread is writing the ProxyMethod.exceptionTypes field from the same object.

      ProxyGenerator.generateProxyClass() always creates a new ProxyGenerator instance and ProxyGenerator.proxyMethods map is private to each ProxyGenerator instance. In most cases, the ProxyMethod instances handled by generateProxyClass() are private to the invoking thread.

      [~jcking] noticed there are following static fields in ProxyGenerator class. Those could be accessed from different threads.

      ```
          /* Preloaded ProxyMethod objects for methods in java.lang.Object */
          private static final ProxyMethod hashCodeMethod;
          private static final ProxyMethod equalsMethod;
          private static final ProxyMethod toStringMethod;
      ```

      It would be good for someone who's familiar with the ProxyGenerator area to take a close look to see if the reported race is benign or needs to be fixed.

            liach Chen Liang
            jiangli Jiangli Zhou
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: