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

Useless (or buggy) call to Math.round on int input

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9, 10
    • Fix Version/s: 12
    • Component/s: client-libs
    • Labels:
      None

      Description

      As discovered by automated code analysis, BasicProgressBarUI.java#getStringPlacement calls Math.round on int input, which is never a good idea, either a useless no-op or a loss of precision for values near Integer.MAX_VALUE. Maybe divide by 2.0 instead of 2?

                  return new Point(x + Math.round(width/2 - stringWidth/2),
                                   y + ((height +
                                       fontSizer.getAscent() -
                                       fontSizer.getLeading() -
                                       fontSizer.getDescent()) / 2));
              } else { // VERTICAL
                  return new Point(x + ((width - fontSizer.getAscent() +
                          fontSizer.getLeading() + fontSizer.getDescent()) / 2),
                          y + Math.round(height/2 - stringWidth/2));

        Attachments

          Activity

            People

            • Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              martin Martin Buchholz
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: