JDK-6244548 : (ch) race in AbstractInterruptibleChannel.blockedOn/initBlockedOn
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2005-03-22
  • Updated: 2010-04-02
  • Resolved: 2005-10-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6Resolved
Related Reports
Relates :  
Description
While reading code I noticed a small race in initBlockedOn in AbstractInterruptibleChannel.  This code attempts to get an accessible Method pointing at Thread.blockedOn without doing any synchronization.  The code as executed should be idempotent so that mostly seems ok.  The problem is that the code publishes the method in blockedOnMethod before it has call setAccessible on it.  This means that another thread could potentially try to use it before the flag was set.  It's extremely unlikely that this could happen but it's still possible.  There are two potential fixes.  One is to put the value into local, call setAccessible and then put it into the static.  I'm still not sure whether any of this code is safe with respect to the Java memory model since no synchronization occurs between the initializing and using threads and the accessible field by definition isn't final so it doesn't enjoy the funny semantics.  The other fix is to avoid reflection all together and use the sun.misc.SharedSecrets mechanism to bind to the needed method directly.  This in general seems better since it avoids the reflective initialization overhead.  This would also address 4653090 which complains about the allocation required for the Method.invoke call.
###@###.### 2005-03-22 23:16:39 GMT

Comments
EVALUATION While it's true that the synchronization issue pointed out does exist in blockedOn()/initBlockedOn() if read these 2 methods alone, but consider the "nasty" static initializer block "workaround" we have at the end the class (yep, it's no longer a lazy initialization any more), is it safe to say that we actually dont have a race condition here since the the first blockedOn() &initBlockOn() invoke happens inside the static initializer and the JVM is responsible of taking care of synchronization. Close as "not a defect". The suggested fix to use SharedSecrets insted of reflection should still be nice to implement, via 4653090.
19-10-2005