JDK-6701459 : Synchronization bug pattern found in javax.management.relation.RelationService
  • Type: Bug
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-05-13
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
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.
7 b28Fixed
Related Reports
Relates :  
William Pugh reports that FindBugs flags the following code from RelationService:

    private Long myNtfSeqNbrCounter = new Long(0);
    private Long getNotificationSequenceNumber() {
	Long result = null;
	synchronized(myNtfSeqNbrCounter) {
	    result = new Long(myNtfSeqNbrCounter.longValue() + 1);
	    myNtfSeqNbrCounter = new Long(result.longValue());
	return result;

This is a well-known bug pattern.  If two threads arrive at the synchronized block at the same time then they will both synchronize on the same Long object.  Whichever of them gets the lock on it first will then update myNtfSeqNbrCounter with a new Long object, but the Java Memory Model does not guarantee that the other one will then see the updated field when it calls myNtfSeqNbrCounter.longValue().

SUGGESTED FIX Use an AtomicLong.

EVALUATION In practice this bug will have zero effect because the Relation Service is very little used; even when it is used there is very little likelihood of parallel updates; and even if the bug is triggered it just means that sequence numbers might repeat. (Almost no clients depend on sequence numbers.) However the fact that this bug is flagged by FindBugs means that we should fix it to avoid adding noise that might hide a more serious bug.