-
Bug
-
Resolution: Fixed
-
P4
-
1.3.1, 1.4.1
-
b18
-
generic, sparc
-
generic, solaris_8
Name: jk109818 Date: 02/27/2003
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
SunOS hardy 5.8 Generic_108528-14 sun4u sparc
SUNW,Sun-Blade-1000
A DESCRIPTION OF THE PROBLEM :
The BoundedRangeModel interface specifies that:
"The minimum and maximum set methods "correct" the other
three properties to accommodate their new value argument.
For example setting the model's minimum may change its
maximum, value, and extent properties (in that order), to
maintain the constraints specified above."
This seems to imply that the extent will only be changed
when necessary to satisfy the constraints. Because of an
integer overflow in the
DefaultBoundedRangeModel.setMinimum() method, the "extent"
is sometimes changed unnecessarily.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Instantiate a DefaultBoundedRangeModel with value of -32768,
extent=Integer.MAX_VALUE and min/max values of
Integer.MIN_VALUE / MAX_VALUE.
2.Call setMinimum(-32767).
EXPECTED VERSUS ACTUAL BEHAVIOR :
The extent should remain the same, since it still satisfies
the constraints.
Actually, it gets set to 0.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.DefaultBoundedRangeModel;
import javax.swing.event.*;
public class RangeTest implements ChangeListener {
DefaultBoundedRangeModel model;
static public void main(String s[]) {
new RangeTest();
}
public RangeTest() {
model = new DefaultBoundedRangeModel(-32768, Integer.MAX_VALUE,
Integer.MIN_VALUE,
Integer.MAX_VALUE);
model.addChangeListener(this);
printState("Initial State");
System.out.println("Set min to -32768");
model.setMinimum(-32768);
}
public void stateChanged(ChangeEvent e) {
printState("... State Changed");
}
private void printState(String msg) {
System.out.println(msg + ": value=" + model.getValue()
+ ", extent=" + model.getExtent()
+ ", min=" + model.getMinimum()
+ ", max=" + model.getMaximum());
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
In the setMinimum() method in DefaultBoundedRangeModel
replace the line:
int newExtent = Math.min(newMax - newValue, extent);
(which is subject to overflow in the "newMax-newValue"
calculation) with:
int newExtent = newValue+extent > newMax ? newMax-newValue
: extent;
(which cannot overflow if the old properties didn't)
(Review ID: 181819)
======================================================================