Following code snippet should write 0.0 to the output:
DoubleProperty p0 = new SimpleDoubleProperty(0.0);
DoubleProperty p05 = new SimpleDoubleProperty(0.5);
DoubleProperty p1 = new SimpleDoubleProperty(1.0);
DoubleProperty p2 = new SimpleDoubleProperty(2.0);
p1.bindBidirectional(p2);
p1.bind(p0);
try {
p2.set(0.5);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(p2.get());
The problem is that setting or binding a bidirectionally bound property (+ the counterpart property is unidirectionally bound) results in an Exception. The old value will not be restored however.
DoubleProperty p0 = new SimpleDoubleProperty(0.0);
DoubleProperty p05 = new SimpleDoubleProperty(0.5);
DoubleProperty p1 = new SimpleDoubleProperty(1.0);
DoubleProperty p2 = new SimpleDoubleProperty(2.0);
p1.bindBidirectional(p2);
p1.bind(p0);
try {
p2.set(0.5);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(p2.get());
The problem is that setting or binding a bidirectionally bound property (+ the counterpart property is unidirectionally bound) results in an Exception. The old value will not be restored however.
- relates to
-
JDK-8092813 When a Bidirectional binding fails, old value restoration may cause an exception hiding the real cause
-
- Resolved
-