JDK-8048209 : SynchronizedNavigableSet tailSet uses wrong mutex
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 8u5
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-06-21
  • Updated: 2015-01-21
  • Resolved: 2014-07-24
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 8 JDK 9
8u40Fixed 9 b26Fixed
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
In the version of the tailSet method taking two arguments, in the implementation of java.util.Collections.SynchronizedNavigableSet, the method creates a new SynchronizedNavigableSet using the default mutex (this) rather than the correct mutex object for that set.

This is the offending code:

    public NavigableSet<E> tailSet(E fromElement, boolean inclusive) {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(ns.tailSet(fromElement, inclusive));
        }
    }

Should be:

    public NavigableSet<E> tailSet(E fromElement, boolean inclusive) {
        synchronized (mutex) {
            return new SynchronizedNavigableSet<>(ns.tailSet(fromElement, inclusive), mutex);
        }
    }


REPRODUCIBILITY :
This bug can be reproduced always.