Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect usage of System.nanoTime() #50

Open
ben-manes opened this issue Jul 11, 2017 · 0 comments
Open

Incorrect usage of System.nanoTime() #50

ben-manes opened this issue Jul 11, 2017 · 0 comments

Comments

@ben-manes
Copy link

ExpiringMap compares nanosecond times as time <= now. Both sides are from direct reads of System.nanoTime(). Unfortunately this violates the contract of that method,

* The value returned represents nanoseconds since some fixed but
* arbitrary <i>origin</i> time (perhaps in the future, so values
* may be negative). 
* ...
* <p>The values returned by this method become meaningful only when
* the difference between two such values, obtained within the same
* instance of a Java virtual machine, is computed.
* ...
* one should use {@code t1 - t0 < 0}, not {@code t1 < t0},
* because of the possibility of numerical overflow.

This behavior is not intuitive and causes these simple oversights. However, failing to abide by that directive can lead to incorrect conclusions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant