From 81e0ab0e7a80581b9b3343b58cc7cbf2782dc7d0 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 a4473e81..30bd329b 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); } }