Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8280459

Suspicious integer division in Hashtable.readHashtable

XMLWordPrintable

    • b07

      SonarCloud warns there is the integer division at (elements / 20), where float division was probably meant:
       int length = (int)((elements + elements / 20) / lf) + 3;

      The apparent intent of that block is to add +5%. I think multiplying by 1.05f is cleaner and safer.

      With elements = 19 and lf = 0.75:
         (int)((elements + elements / 20) / lf) + 3 = 28
         (int)(elements * 1.05f / lf) + 3 = 29

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: