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

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 12
    • 9, 10
    • client-libs
    • None

      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));

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

              Created:
              Updated:
              Resolved: