FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
In class com.sun.javafx.binding.SelectBinding, there are several convenience methods for computing values for data types (String, Boolean, Double, etc.).
In each of these methods, the property itself is checked for null, but after this, the value of the property is directly accessed by, e.g. 'observable.getValue().toString();' in nested class SelectBinding.AsString.
This error only occurs, as long as the binding in invalid. As soon as it has ben validated, the result of method get() is returned, which then simply returns 'null'.
This may raise a wrong NullPointerException if the value of the property is null, which is a common and legal use case.
A better way would be (in my opinion) to check for null-value right after checking for null on property and return the default value, if the value is null.
In fact, the exception is caught/handled, so the application keeps on running and there are no side-effects, but we get a lot of unnecessary exceptions, which pollute or logs!
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See example code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The default value should be returned.
ACTUAL -
see ErrorMessages
ERROR MESSAGES/STACK TRACES THAT OCCUR :
The posted example code results in this exceptions:
WARNING: Exception while evaluating select-binding
java.lang.NullPointerException
at com.sun.javafx.binding.SelectBinding$AsString.computeValue(SelectBinding.java:399)
at javafx.beans.binding.StringBinding.get(StringBinding.java:152)
at spielwiese.SelectBindingError.main(SelectBindingError.java:15)
null
Jul 25, 2016 11:35:51 AM com.sun.javafx.binding.SelectBinding$AsString computeValue
WARNING: Exception while evaluating select-binding
java.lang.NullPointerException
at com.sun.javafx.binding.SelectBinding$AsString.computeValue(SelectBinding.java:399)
at javafx.beans.binding.StringBinding.get(StringBinding.java:152)
at javafx.beans.binding.StringBinding.get(StringBinding.java:61)
at javafx.beans.binding.StringExpression.getValue(StringExpression.java:51)
at spielwiese.SelectBindingError.main(SelectBindingError.java:16)
Jul 25, 2016 11:35:51 AM com.sun.javafx.binding.SelectBinding$AsString computeValue
WARNING: Exception while evaluating select-binding
java.lang.NullPointerException
at com.sun.javafx.binding.SelectBinding$AsString.computeValue(SelectBinding.java:399)
at javafx.beans.binding.StringBinding.get(StringBinding.java:152)
at javafx.beans.binding.StringBinding.get(StringBinding.java:61)
at javafx.beans.binding.StringExpression.getValueSafe(StringExpression.java:62)
at spielwiese.SelectBindingError.main(SelectBindingError.java:17)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public final class SelectBindingError {
public static void main(final String[] args) {
final ObjectProperty<SelectBindingError> root =
new SimpleObjectProperty<SelectBindingError>(new SelectBindingError());
System.out.println(Bindings.selectString(root, "nullValueProperty").get());
System.out.println(Bindings.selectString(root, "nullValueProperty").getValue());
System.out.println(Bindings.selectString(root, "nullValueProperty").getValueSafe());
}
private final StringProperty nullValue = new SimpleStringProperty();
public String getNullValueProperty() {
return this.nullValueProperty().get();
}
private StringProperty nullValueProperty() {
return this.nullValue;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If using a logger, it could be configured so that this special kind of exception is no longer visible/logged.
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
In class com.sun.javafx.binding.SelectBinding, there are several convenience methods for computing values for data types (String, Boolean, Double, etc.).
In each of these methods, the property itself is checked for null, but after this, the value of the property is directly accessed by, e.g. 'observable.getValue().toString();' in nested class SelectBinding.AsString.
This error only occurs, as long as the binding in invalid. As soon as it has ben validated, the result of method get() is returned, which then simply returns 'null'.
This may raise a wrong NullPointerException if the value of the property is null, which is a common and legal use case.
A better way would be (in my opinion) to check for null-value right after checking for null on property and return the default value, if the value is null.
In fact, the exception is caught/handled, so the application keeps on running and there are no side-effects, but we get a lot of unnecessary exceptions, which pollute or logs!
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See example code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The default value should be returned.
ACTUAL -
see ErrorMessages
ERROR MESSAGES/STACK TRACES THAT OCCUR :
The posted example code results in this exceptions:
WARNING: Exception while evaluating select-binding
java.lang.NullPointerException
at com.sun.javafx.binding.SelectBinding$AsString.computeValue(SelectBinding.java:399)
at javafx.beans.binding.StringBinding.get(StringBinding.java:152)
at spielwiese.SelectBindingError.main(SelectBindingError.java:15)
null
Jul 25, 2016 11:35:51 AM com.sun.javafx.binding.SelectBinding$AsString computeValue
WARNING: Exception while evaluating select-binding
java.lang.NullPointerException
at com.sun.javafx.binding.SelectBinding$AsString.computeValue(SelectBinding.java:399)
at javafx.beans.binding.StringBinding.get(StringBinding.java:152)
at javafx.beans.binding.StringBinding.get(StringBinding.java:61)
at javafx.beans.binding.StringExpression.getValue(StringExpression.java:51)
at spielwiese.SelectBindingError.main(SelectBindingError.java:16)
Jul 25, 2016 11:35:51 AM com.sun.javafx.binding.SelectBinding$AsString computeValue
WARNING: Exception while evaluating select-binding
java.lang.NullPointerException
at com.sun.javafx.binding.SelectBinding$AsString.computeValue(SelectBinding.java:399)
at javafx.beans.binding.StringBinding.get(StringBinding.java:152)
at javafx.beans.binding.StringBinding.get(StringBinding.java:61)
at javafx.beans.binding.StringExpression.getValueSafe(StringExpression.java:62)
at spielwiese.SelectBindingError.main(SelectBindingError.java:17)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public final class SelectBindingError {
public static void main(final String[] args) {
final ObjectProperty<SelectBindingError> root =
new SimpleObjectProperty<SelectBindingError>(new SelectBindingError());
System.out.println(Bindings.selectString(root, "nullValueProperty").get());
System.out.println(Bindings.selectString(root, "nullValueProperty").getValue());
System.out.println(Bindings.selectString(root, "nullValueProperty").getValueSafe());
}
private final StringProperty nullValue = new SimpleStringProperty();
public String getNullValueProperty() {
return this.nullValueProperty().get();
}
private StringProperty nullValueProperty() {
return this.nullValue;
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
If using a logger, it could be configured so that this special kind of exception is no longer visible/logged.
- relates to
-
JDK-8091242 Bindings.select methods inefficiently implemented
- Open