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

Avoid division by 0 in java/awt/font/TextJustifier.java justify

XMLWordPrintable

    • 2d
    • b22
    • generic
    • generic

        In java/awt/font/TextJustifier.java justify there is a potential code path where divison by zero might happen , see also the Sonar finding :

        https://sonarcloud.io/project/issues?id=shipilev_jdk&open=AXcqMwpm8sPJZZzONu1k&resolved=false&severities=CRITICAL&types=BUG


                    boolean hitLimit = (weight == 0) || (!lastPass && ((delta < 0) == (delta < gslimit)));
                    boolean absorbing = hitLimit && absorbweight > 0;
                    // predivide delta by weight
                    float weightedDelta = delta / weight; // not used if weight == 0

        In case of (weight == 0) the division should not be done because the value of weightedDelta is unused in this case anyway.

              mbaesken Matthias Baesken
              mbaesken Matthias Baesken
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: