-
-
Notifications
You must be signed in to change notification settings - Fork 1
GH-221 NPE in CollectionGui from null parcel content items #223
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9ccf34c
fix: strip null/empty item stacks from parcel content (#221)
Jakubk15 1ecdb8e
fix: stop using legacy ItemStack serialization for parcel content
Jakubk15 dbfde43
Update src/main/java/com/eternalcode/parcellockers/content/ParcelCont…
Jakubk15 a1ed767
test: cover null items list in ParcelContent guard
Jakubk15 9d5ca43
Merge branch 'master' into fix/issue-221-collection-gui-npe
Jakubk15 c8c0a0c
fix: guard against null parcel description in AdminParcelEditGui
Jakubk15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
45 changes: 45 additions & 0 deletions
45
src/test/java/com/eternalcode/parcellockers/content/ParcelContentTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.eternalcode.parcellockers.content; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ParcelContentTest { | ||
|
|
||
| @Test | ||
| void dropsNullItems() { | ||
| // Reproduces issue #221: a null element in the content list makes CollectionGui | ||
| // NPE on itemStack.getType(). The model must never expose null items. | ||
| ItemStack stone = mock(ItemStack.class); | ||
|
|
||
| ParcelContent content = new ParcelContent(UUID.randomUUID(), Arrays.asList(stone, null)); | ||
|
|
||
| assertEquals(List.of(stone), content.items()); | ||
| } | ||
|
|
||
| @Test | ||
| void dropsEmptyItems() { | ||
| // Empty/air slots can slip past the GUI write filters; they must not be exposed | ||
| // as content, otherwise they round-trip through the persister as nulls. | ||
| ItemStack stone = mock(ItemStack.class); | ||
| ItemStack air = mock(ItemStack.class); | ||
| when(air.isEmpty()).thenReturn(true); | ||
|
|
||
| ParcelContent content = new ParcelContent(UUID.randomUUID(), List.of(stone, air)); | ||
|
|
||
| assertEquals(List.of(stone), content.items()); | ||
| } | ||
|
|
||
| @Test | ||
| void handlesNullItemsList() { | ||
| ParcelContent content = new ParcelContent(UUID.randomUUID(), null); | ||
|
|
||
| assertEquals(List.of(), content.items()); | ||
| } | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
...t/java/com/eternalcode/parcellockers/gui/implementation/admin/AdminParcelEditGuiTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package com.eternalcode.parcellockers.gui.implementation.admin; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class AdminParcelEditGuiTest { | ||
|
|
||
| @Test | ||
| @DisplayName("Should return empty string for a null placeholder value") | ||
| void nullToEmptyWhenValueIsNull() { | ||
| assertEquals("", AdminParcelEditGui.nullToEmpty(null)); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Should return the original value when not null") | ||
| void nullToEmptyWhenValueIsNotNull() { | ||
| assertEquals("desc", AdminParcelEditGui.nullToEmpty("desc")); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Should not throw when substituting a null parcel description into a template") | ||
| void replaceWithNullDescriptionDoesNotThrow() { | ||
| String template = "Description: {DESCRIPTION}"; | ||
| assertDoesNotThrow(() -> template.replace("{DESCRIPTION}", AdminParcelEditGui.nullToEmpty(null))); | ||
| assertEquals("Description: ", template.replace("{DESCRIPTION}", AdminParcelEditGui.nullToEmpty(null))); | ||
| } | ||
| } |
Oops, something went wrong.
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.
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.
It would be beneficial to add a unit test to verify that the compact constructor correctly handles a
nullitems list by defaulting to an empty list, ensuring full coverage of the defensive guard.