Skip to content

Commit 7857022

Browse files
TheMrMilchmannnlisker
authored andcommitted
8251946: ObservableList.setAll does not conform to specification
Reviewed-by: arapte, kcr
1 parent 1c485a3 commit 7857022

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

modules/javafx.base/src/main/java/com/sun/javafx/collections/VetoableListDecorator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ public boolean setAll(Collection<? extends E> col) {
113113
onProposedChange(Collections.unmodifiableList(new ArrayList(col)), 0, size());
114114
try {
115115
modCount++;
116-
list.setAll(col);
117-
return true;
116+
return list.setAll(col);
118117
} catch(Exception e) {
119118
modCount--;
120119
throw e;

modules/javafx.base/src/main/java/javafx/collections/ModifiableObservableListBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ public ModifiableObservableListBase() {
8888

8989
@Override
9090
public boolean setAll(Collection<? extends E> col) {
91+
if (isEmpty() && col.isEmpty()) return false;
9192
beginChange();
9293
try {
9394
clear();
9495
addAll(col);
96+
return true;
9597
} finally {
9698
endChange();
9799
}
98-
return true;
99100
}
100101

101102
@Override

modules/javafx.base/src/test/java/test/javafx/collections/ObservableListTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,29 @@ public void testSet() {
255255
assertEquals("two", r);
256256
}
257257

258+
@Test
259+
public void testSetAll() {
260+
useListData("one", "two", "three");
261+
boolean r = list.setAll("one");
262+
assertTrue(r);
263+
264+
r = list.setAll("one", "four", "five");
265+
assertTrue(r);
266+
267+
r = list.setAll();
268+
assertTrue(r);
269+
270+
r = list.setAll("one");
271+
assertTrue(r);
272+
}
273+
274+
@Test
275+
public void testSetAllNoUpdate() {
276+
useListData();
277+
boolean r = list.setAll();
278+
assertFalse(r);
279+
}
280+
258281
@Test
259282
public void testObserverCanRemoveObservers() {
260283
final ListChangeListener<String> listObserver = change -> {

0 commit comments

Comments
 (0)