-
Notifications
You must be signed in to change notification settings - Fork 84
Fix crash caused by pressing TAB #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MattSturgeon
commented
Mar 22, 2023
common/src/main/java/me/shedaniel/clothconfig2/gui/widget/SearchFieldEntry.java
Show resolved
Hide resolved
`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 shedaniel#176 [1]: https://docs.oracle.com/javase/8/docs/api/java/util/List.html#indexOf-java.lang.Object-
shedaniel
approved these changes
Mar 23, 2023
Owner
shedaniel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM
|
@shedaniel merge? |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
Owner
|
Thanks for reminding me! I will merge it this weekend! |
This comment was marked as duplicate.
This comment was marked as duplicate.
Contributor
Author
|
@shedaniel it'd be great to get this merged 😄 |
shedaniel
pushed a commit
that referenced
this pull request
Dec 21, 2023
`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-
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #176, which was caused by
SearchFieldEntry.children()usingList.of()to form the list of children.List.of()returns an unmodifiable list, which doesn't permitnullmembers. This means thatList.indexOf()will throw aNullPointerExceptionwhennullis passes to it, reveals a bug in the vanilla methodContainerEventHandler#changeFocus(boolean).ContainerEventHandler.changeFocus()with comments regarding the vanilla bugThis PR fixes the issue by having
SearchFieldEntry.children()useCollections.singletonList()instead ofList.of(). Singleton lists permitnullvalues, soindexOf()doesn't need to throw any exceptions when we ask for the index ofnull.I've also included a couple commits fixing mapping names I stumbled across while debugging. I can open a separate PR for those if you like, but I figured so long as the commits don't get squashed together when merging one small PR should be ok. EDIT: moved to #202