BoxView#calculateMinorAxisRequirements meaningless Math.max

Andrey Turbanov turbanoff at gmail.com
Thu Sep 16 08:00:57 UTC 2021


Hello.
I found suspicious code in the
javax.swing.text.BoxView#calculateMinorAxisRequirements method, when I
checked warnings from IntelliJ IDEA.
https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/javax/swing/text/BoxView.java#L906
```
int min = 0;
long pref = 0;
int max = Integer.MAX_VALUE;
int n = getViewCount();
for (int i = 0; i < n; i++) {
    View v = getView(i);
    min = Math.max((int) v.getMinimumSpan(axis), min);
    pref = Math.max((int) v.getPreferredSpan(axis), pref);
    max = Math.max((int) v.getMaximumSpan(axis), max);
}
```

It calls Math.max(int, int) method with a second argument Integer.MAX_VALUE.
This call is useless, as the result will always be Integer.MAX_VALUE.
Looks like initial values for max/min variables are mixed up.

Andrey Turbanov



More information about the client-libs-dev mailing list