From 461ae8e56fa02f0422e2b8a3b1f38d743e5fba7e Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Thu, 21 Dec 2023 10:10:51 +0000 Subject: [PATCH] Fix NPE crash when changing focus using TAB (#201) `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- --- .../shedaniel/clothconfig2/gui/widget/SearchFieldEntry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/SearchFieldEntry.java b/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/SearchFieldEntry.java index 79eed189..e383a034 100644 --- a/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/SearchFieldEntry.java +++ b/common/src/main/java/me/shedaniel/clothconfig2/gui/widget/SearchFieldEntry.java @@ -132,11 +132,11 @@ public Optional getDefaultValue() { @Override public List narratables() { - return List.of(editBox); + return Collections.singletonList(editBox); } @Override public List children() { - return List.of(editBox); + return Collections.singletonList(editBox); } }