11/*
2- * Copyright (c) 2010, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2010, 2026 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2626package test .javafx .collections ;
2727
2828import com .sun .javafx .collections .ObservableListWrapper ;
29+
2930import java .util .Arrays ;
3031import java .util .Collections ;
3132import java .util .List ;
3637import javafx .collections .ObservableList ;
3738import javafx .collections .ObservableListWrapperShim ;
3839import javafx .collections .transformation .FilteredList ;
40+ import org .junit .jupiter .api .AfterEach ;
3941import org .junit .jupiter .api .BeforeEach ;
4042import org .junit .jupiter .api .Test ;
4143
@@ -55,6 +57,19 @@ public void setUp() {
5557 mlo = new MockListObserver <>();
5658 filteredList = new FilteredList <>(list , predicate );
5759 filteredList .addListener (mlo );
60+
61+ Thread .currentThread ().setUncaughtExceptionHandler ((thread , throwable ) -> {
62+ if (throwable instanceof RuntimeException ) {
63+ throw (RuntimeException )throwable ;
64+ } else {
65+ Thread .currentThread ().getThreadGroup ().uncaughtException (thread , throwable );
66+ }
67+ });
68+ }
69+
70+ @ AfterEach
71+ void tearDown () {
72+ Thread .currentThread ().setUncaughtExceptionHandler (null );
5873 }
5974
6075 @ Test
@@ -321,4 +336,20 @@ public void testGetViewIndexOutOfBounds() {
321336 assertThrows (IndexOutOfBoundsException .class , () -> filteredList .getViewIndex (list .size ()));
322337 assertDoesNotThrow (() -> filteredList .getViewIndex (filteredList .size ()));
323338 }
339+
340+ @ Test
341+ public void testSortedThenFilteredListDoesNotThrowIOOBE () {
342+ ObservableList <Long > numbers = FXCollections .observableArrayList ();
343+
344+ ObservableList <Long > sortedList = numbers .sorted (Long ::compare );
345+ ObservableList <Long > filteredList = sortedList .filtered (_ -> true );
346+
347+ numbers .add (0L );
348+ numbers .addAll (List .of (0L , 4L , 8L , 2L , 6L , 0L , 4L , 8L , 2L , 6L , 0L ));
349+
350+ assertDoesNotThrow (() -> numbers .subList (0 , numbers .size () - 1 ).clear ());
351+
352+ assertEquals (List .of (0L ), filteredList );
353+ assertEquals (List .of (0L ), sortedList );
354+ }
324355}
0 commit comments