Description
FULL PRODUCT VERSION :
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode, sharing)
(I hav also tried this on update 40 - same bug. update 20 - works fine)
ADDITIONAL OS VERSION INFORMATION :
I have tried this on
Microsoft Windows [Version 6.1.7601]
and
Linux 3.19.0-28-generic #30-Ubuntu SMP Mon Aug 31 15:52:51 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
If you remove one ChangeListener from MapProperty instance, all the change listeners added prior removal will be actually removed. According to javadoc (and java 1.8.0 update 20 version) it should only remove one listener - the one passed in the parameter.
ADDITIONAL REGRESSION INFORMATION:
There is no bug in this version of java:
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Create empty java project
2) Create new MapProperty instance
3) Add two ChangeListeners, that print some output when being executed (lets say: executing listener 1 and executing listener 2
4) remove only one of the two listeners
5) setValue with new observable map instance for the MapProperty instance
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Only one listener being removed
---------------
Output from my test case:
executing listener 1
executing listener 2
---- removing listener now -----
executing listener 2
ACTUAL -
Both listeners are removed
-----------
Output from my test case:
executing listener 1
executing listener 2
---- removing listener now -----
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.HashMap;
import javafx.beans.property.MapProperty;
import javafx.beans.property.SimpleMapProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
public class MapTest {
public static void main(String[] args) {
MapProperty<String, Object> mapProp = new SimpleMapProperty<>(FXCollections.observableMap(
new HashMap<String, Object>()));
ChangeListener<ObservableMap<String, Object>> listener1
= (ObservableValue<? extends ObservableMap<String, Object>> obs, ObservableMap<String, Object> oldV, ObservableMap<String, Object> newV) -> {
System.out.println("executing listener 1");
};
ChangeListener<ObservableMap<String, Object>> listener2
= (ObservableValue<? extends ObservableMap<String, Object>> obs, ObservableMap<String, Object> oldV, ObservableMap<String, Object> newV) -> {
System.out.println("executing listener 2");
};
mapProp.addListener(listener1);
mapProp.addListener(listener2);
mapProp.setValue(FXCollections.observableMap(
new HashMap<String, Object>()));
System.out.println("---- removing listener now -----");
mapProp.removeListener(listener1);
mapProp.setValue(FXCollections.observableMap(
new HashMap<String, Object>()));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I have not found one yet but I assume I could make my own list of listeners and manage adding and removing listeners by my own mechanism.
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) Client VM (build 25.60-b23, mixed mode, sharing)
(I hav also tried this on update 40 - same bug. update 20 - works fine)
ADDITIONAL OS VERSION INFORMATION :
I have tried this on
Microsoft Windows [Version 6.1.7601]
and
Linux 3.19.0-28-generic #30-Ubuntu SMP Mon Aug 31 15:52:51 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
If you remove one ChangeListener from MapProperty instance, all the change listeners added prior removal will be actually removed. According to javadoc (and java 1.8.0 update 20 version) it should only remove one listener - the one passed in the parameter.
ADDITIONAL REGRESSION INFORMATION:
There is no bug in this version of java:
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Create empty java project
2) Create new MapProperty instance
3) Add two ChangeListeners, that print some output when being executed (lets say: executing listener 1 and executing listener 2
4) remove only one of the two listeners
5) setValue with new observable map instance for the MapProperty instance
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Only one listener being removed
---------------
Output from my test case:
executing listener 1
executing listener 2
---- removing listener now -----
executing listener 2
ACTUAL -
Both listeners are removed
-----------
Output from my test case:
executing listener 1
executing listener 2
---- removing listener now -----
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.HashMap;
import javafx.beans.property.MapProperty;
import javafx.beans.property.SimpleMapProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableMap;
public class MapTest {
public static void main(String[] args) {
MapProperty<String, Object> mapProp = new SimpleMapProperty<>(FXCollections.observableMap(
new HashMap<String, Object>()));
ChangeListener<ObservableMap<String, Object>> listener1
= (ObservableValue<? extends ObservableMap<String, Object>> obs, ObservableMap<String, Object> oldV, ObservableMap<String, Object> newV) -> {
System.out.println("executing listener 1");
};
ChangeListener<ObservableMap<String, Object>> listener2
= (ObservableValue<? extends ObservableMap<String, Object>> obs, ObservableMap<String, Object> oldV, ObservableMap<String, Object> newV) -> {
System.out.println("executing listener 2");
};
mapProp.addListener(listener1);
mapProp.addListener(listener2);
mapProp.setValue(FXCollections.observableMap(
new HashMap<String, Object>()));
System.out.println("---- removing listener now -----");
mapProp.removeListener(listener1);
mapProp.setValue(FXCollections.observableMap(
new HashMap<String, Object>()));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I have not found one yet but I assume I could make my own list of listeners and manage adding and removing listeners by my own mechanism.