<Swing Dev> [12] RFR: JDK-8205535:Useless (or buggy) call to Math.round on int input

Prasanta Sadhukhan prasanta.sadhukhan at oracle.com
Thu Jul 19 09:57:46 UTC 2018


A correction on the fix. Correct modification is this one

--- 
a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicProgressBarUI.java 
Fri Jun 15 13:07:46 2018 -0700
+++ 
b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicProgressBarUI.java 
Thu Jul 19 15:26:28 2018 +0530
@@ -874,7 +874,7 @@
progressString);

          if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
-            return new Point(x + Math.round(width/2 - stringWidth/2),
+            return new Point(x + (int)Math.round(width/2.0 - 
stringWidth/2.0),
                               y + ((height +
                                   fontSizer.getAscent() -
                                   fontSizer.getLeading() -
@@ -882,7 +882,7 @@
          } else { // VERTICAL
              return new Point(x + ((width - fontSizer.getAscent() +
                      fontSizer.getLeading() + fontSizer.getDescent()) / 2),
-                    y + Math.round(height/2 - stringWidth/2));
+                    y + (int)Math.round(height/2.0 - stringWidth/2.0));
          }
      }

Regards
Prasanta
On 7/19/2018 2:54 PM, Prasanta Sadhukhan wrote:
> Hi All,
>
> Please review a simple fix to rectify invocation of Math.round() with 
> double/float value instead of int
>
> --- 
> a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicProgressBarUI.java 
> Fri Jun 15 13:07:46 2018 -0700
> +++ 
> b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicProgressBarUI.java 
> Thu Jul 19 14:51:20 2018 +0530
> @@ -874,7 +874,7 @@
> progressString);
>
>          if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
> -            return new Point(x + Math.round(width/2 - stringWidth/2),
> +            return new Point(x + Math.round(width/2.0 - 
> stringWidth/2.0),
>                               y + ((height +
>                                   fontSizer.getAscent() -
>                                   fontSizer.getLeading() -
> @@ -882,7 +882,7 @@
>          } else { // VERTICAL
>              return new Point(x + ((width - fontSizer.getAscent() +
>                      fontSizer.getLeading() + fontSizer.getDescent()) 
> / 2),
> -                    y + Math.round(height/2 - stringWidth/2));
> +                    y + Math.round(height/2.0 - stringWidth/2.0));
>          }
>      }
>
> Similar thing was done for
>     protected int getBoxLength(int availableLength, int otherDimension) {
>         return (int)Math.round(availableLength/6.0);
>     }
>
> Regards
> Prasanta



More information about the swing-dev mailing list