1212 *******************************************************************************/
1313package org .eclipse .fx .core .collection .internal ;
1414
15- import java .lang .reflect .InvocationTargetException ;
16- import java .lang .reflect .Method ;
1715import java .util .ArrayList ;
1816import java .util .List ;
1917import java .util .OptionalLong ;
@@ -104,6 +102,37 @@ public void moveBy(long delta) {
104102 // TODO need to handle long overflow
105103 this .index .set (Math .max (0 , this .index .get () + delta ));
106104 }
105+
106+ // Overrides to resolve diamond inheritance conflicts with JavaFX 21+ default methods
107+ @ Override
108+ public javafx .beans .value .ObservableValue <T > when (javafx .beans .value .ObservableValue <Boolean > condition ) {
109+ return super .when (condition );
110+ }
111+
112+ @ Override
113+ public javafx .util .Subscription subscribe (java .util .function .Consumer <? super T > subscriber ) {
114+ return super .subscribe (subscriber );
115+ }
116+
117+ @ Override
118+ public javafx .util .Subscription subscribe (java .util .function .BiConsumer <? super T , ? super T > subscriber ) {
119+ return super .subscribe (subscriber );
120+ }
121+
122+ @ Override
123+ public <U > javafx .beans .value .ObservableValue <U > map (java .util .function .Function <? super T , ? extends U > mapper ) {
124+ return super .map (mapper );
125+ }
126+
127+ @ Override
128+ public javafx .beans .value .ObservableValue <T > orElse (T value ) {
129+ return super .orElse (value );
130+ }
131+
132+ @ Override
133+ public <U > javafx .beans .value .ObservableValue <U > flatMap (java .util .function .Function <? super T , ? extends javafx .beans .value .ObservableValue <? extends U >> mapper ) {
134+ return super .flatMap (mapper );
135+ }
107136 }
108137
109138 class ListViewImpl extends ObservableListBase <T > implements IndexRangeView <T > {
@@ -119,9 +148,7 @@ public ListViewImpl(long startIndex, int length) {
119148 FXObservableUtil .onInvalidate (this .length , v -> updateList ());
120149 FXObservableUtil .onInvalidate (VirtualObservableList .this .list , o -> updateList ());
121150
122- this .listener = (c ) -> {
123- fireChange (new SourceChangeEvent <T >(this , c ));
124- };
151+ this .listener = (c ) -> fireChange (new SourceChangeEvent <T >(this , c ));
125152 this .data .addListener (this .listener );
126153 updateList ();
127154 }
@@ -134,7 +161,7 @@ private void updateList() {
134161 (int ) Math .min (_endIndex () + 1 , VirtualObservableList .this .list .size ())));
135162 }
136163
137- // Fill up the reset of the list
164+ // Fill up the rest of the list
138165 if (list .size () < size ()) {
139166 for (int i = list .size (); i < size (); i ++) {
140167 list .add (null );
@@ -209,22 +236,30 @@ public T get(int index) {
209236 public int size () {
210237 return this .length .get ();
211238 }
239+
240+ // Overrides to resolve diamond inheritance conflicts with JavaFX 21+ default methods
241+ @ Override
242+ public javafx .collections .transformation .FilteredList <T > filtered (java .util .function .Predicate <T > predicate ) {
243+ return super .filtered (predicate );
244+ }
245+
246+ @ Override
247+ public javafx .collections .transformation .SortedList <T > sorted (java .util .Comparator <T > comparator ) {
248+ return super .sorted (comparator );
249+ }
250+
251+ @ Override
252+ public javafx .collections .transformation .SortedList <T > sorted () {
253+ return super .sorted ();
254+ }
212255 }
213256
214257 static class SourceChangeEvent <T > extends ListChangeListener .Change <T > {
215258 private final Change <? extends T > change ;
216- private final Method getPermutation ;
217259
218260 public SourceChangeEvent (ObservableList <T > list , Change <? extends T > change ) {
219261 super (list );
220262 this .change = change ;
221- try {
222- // TODO We should use MethodHandles
223- this .getPermutation = ListChangeListener .Change .class .getDeclaredMethod ("getPermutation" ); //$NON-NLS-1$
224- this .getPermutation .setAccessible (true );
225- } catch (NoSuchMethodException | SecurityException e ) {
226- throw new IllegalStateException (e );
227- }
228263 }
229264
230265 @ Override
@@ -255,11 +290,18 @@ public List<T> getRemoved() {
255290
256291 @ Override
257292 protected int [] getPermutation () {
258- try {
259- return (int []) this .getPermutation .invoke (this .change );
260- } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
261- throw new IllegalStateException (e );
293+ // Use the public getPermutation(int) method instead of reflection
294+ // to access the protected getPermutation() method
295+ if (!this .change .wasPermutated ()) {
296+ return new int [0 ];
297+ }
298+ int from = this .change .getFrom ();
299+ int to = this .change .getTo ();
300+ int [] perm = new int [to - from ];
301+ for (int i = from ; i < to ; i ++) {
302+ perm [i - from ] = this .change .getPermutation (i );
262303 }
304+ return perm ;
263305 }
264306
265307 @ Override
0 commit comments