Skip to content

Commit

Permalink
Fix NPE crash when changing focus using TAB (#201)
Browse files Browse the repository at this point in the history
`SearchFieldEntry.children()` was returning `List.of(editBox)`, which itself returns an "unmodifiable" list.

Unmodifiable lists do not permit null entries, and [`indexOf()` will throw a `NullPointerException`][1] if the specified element is `null` and the list does not permit `null` elements.
This reveals a bug in vanilla's `ContainerEventHandler#changeFocus(boolean)` method, where `indexOf()` is called without a null-check, causing the crash.

Instead, we can use `Collections.singletonList()` which returns a `SingletonList`. Still immutable, but no silly NPEs.

Fixes #176

[1]: https://docs.oracle.com/javase/8/docs/api/java/util/List.html#indexOf-java.lang.Object-
  • Loading branch information
MattSturgeon authored Dec 21, 2023
1 parent e216516 commit 461ae8e
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ public Optional<Object> getDefaultValue() {

@Override
public List<? extends NarratableEntry> narratables() {
return List.of(editBox);
return Collections.singletonList(editBox);
}

@Override
public List<? extends GuiEventListener> children() {
return List.of(editBox);
return Collections.singletonList(editBox);
}
}

0 comments on commit 461ae8e

Please sign in to comment.