Skip to content

Commit 3c02eba

Browse files
authored
refactor: align exception type with grid (#8121)
1 parent 362be0a commit 3c02eba

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/treegrid/TreeGrid.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ int setViewportRangeByIndexPath(int[] path, int padding) {
11431143
*
11441144
* @param item
11451145
* the item to scroll to
1146-
* @throws IllegalArgumentException
1146+
* @throws NoSuchElementException
11471147
* if the item does not belong to the tree
11481148
*/
11491149
@Override

vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/treegrid/TreeGridDataCommunicator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.ArrayList;
1919
import java.util.LinkedList;
2020
import java.util.List;
21+
import java.util.NoSuchElementException;
2122

2223
import com.vaadin.flow.data.provider.ArrayUpdater;
2324
import com.vaadin.flow.data.provider.CompositeDataGenerator;
@@ -107,7 +108,7 @@ private int[] getIndexPath(T item, List<T> ancestors) {
107108
var itemIndex = getItemIndex(item,
108109
path.isEmpty() ? null : ancestors.get(ancestors.size() - 1));
109110
if (itemIndex == -1) {
110-
throw new IllegalArgumentException("Item does not exist.");
111+
throw new NoSuchElementException("Item does not exist.");
111112
}
112113
path.add(itemIndex);
113114
return path.stream().mapToInt(i -> i).toArray();
@@ -138,7 +139,7 @@ private List<Integer> getAncestorPath(List<T> ancestors) {
138139
var ancestorIndex = getItemIndex(ancestors.get(i),
139140
i == 0 ? null : ancestors.get(i - 1));
140141
if (ancestorIndex == -1) {
141-
throw new IllegalArgumentException("Item does not exist.");
142+
throw new NoSuchElementException("Item does not exist.");
142143
}
143144
ancestorPath.add(ancestorIndex);
144145
}

vaadin-grid-flow-parent/vaadin-grid-flow/src/test/java/com/vaadin/flow/component/treegrid/ScrollToItemTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.vaadin.flow.component.treegrid;
1717

1818
import java.util.List;
19+
import java.util.NoSuchElementException;
1920
import java.util.stream.IntStream;
2021
import java.util.stream.Stream;
2122

@@ -140,7 +141,7 @@ public void treeDataProvider_nestedHierarchyFormat_scrollToItemWithCollapsedPare
140141
public void treeDataProvider_flattenedHierarchyFormat_scrollToMissingItem_doesNotScroll() {
141142
treeGrid.setDataProvider(new TreeDataProvider<>(treeData,
142143
HierarchicalDataProvider.HierarchyFormat.FLATTENED));
143-
Assert.assertThrows(IllegalArgumentException.class,
144+
Assert.assertThrows(NoSuchElementException.class,
144145
this::scrollToMissingItem);
145146
assertNotScrolled();
146147
}
@@ -149,7 +150,7 @@ public void treeDataProvider_flattenedHierarchyFormat_scrollToMissingItem_doesNo
149150
public void treeDataProvider_nestedHierarchyFormat_scrollToMissingItem_doesNotScroll() {
150151
treeGrid.setDataProvider(new TreeDataProvider<>(treeData,
151152
HierarchicalDataProvider.HierarchyFormat.NESTED));
152-
Assert.assertThrows(IllegalArgumentException.class,
153+
Assert.assertThrows(NoSuchElementException.class,
153154
this::scrollToMissingItem);
154155
assertNotScrolled();
155156
}

0 commit comments

Comments
 (0)