RFR [6853696] (ref) ReferenceQueue.remove(timeout) may return null even if timeout has not expired

roger riggs roger.riggs at oracle.com
Mon Feb 24 14:37:29 UTC 2014

Hi Ivan,

The code is correct as written but there might be some creep in the end 
time due to the sampling of System.nanoTime.

I would be inclined to calculate the final time of the timeout once
and then compare simply with the current nanotime.

long end = (timeout == 0) ? Long.MAX_VALUE : (System.nanoTime() + 
timeout * 1000000);

Then the test in the loop can be:

   if (System.nanoTime() > end) {
      return null;

Roger (Not a Reviewer)

On 2/24/2014 12:59 AM, Ivan Gerasimov wrote:
> Hello!
> ReferenceQueue.remove(timeout) may return too early, i.e. before the 
> specified timeout has elapsed.
> Would you please review the fix?
> The change also includes a regression test, which can be used to 
> demonstrate the issue.
> BUGURL: https://bugs.openjdk.java.net/browse/JDK-6853696
> WEBREV: http://cr.openjdk.java.net/~igerasim/6853696/0/webrev/
> Sincerely yours,
> Ivan

More information about the core-libs-dev mailing list