Uploaded image for project: 'Apache Cassandra'
  1. Apache Cassandra
  2. CASSANDRA-5584

Incorrect use of System.nanoTime()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Low
    • Resolution: Fixed
    • 1.2.6
    • None
    • None
    • Low

    Description

      From System.nanoTime() JavaDoc:

      For example, to measure how long some code takes to execute:
       long startTime = System.nanoTime();
       // ... the code being measured ...
       long estimatedTime = System.nanoTime() - startTime; 
      
      To compare two nanoTime values
       long t0 = System.nanoTime();
       ...
       long t1 = System.nanoTime();
      one should use t1 - t0 < 0, not t1 < t0, because of the possibility of numerical overflow.
      

      I found one place with such incorrect use that can result in overflow and in incorrect timeout handling. See attached patch.

      Attachments

        1. trunk-5584.txt
          1 kB
          Mikhail Mazursky

        Activity

          People

            ash2k Mikhail Mazursky
            ash2k Mikhail Mazursky
            Mikhail Mazursky
            Jonathan Ellis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: