Skip to content

Guard against NPE from NamespacedKey.fromString() returning null in loadLimits()#249

Merged
tastybento merged 2 commits intodevelopfrom
copilot/sub-pr-247
Mar 22, 2026
Merged

Guard against NPE from NamespacedKey.fromString() returning null in loadLimits()#249
tastybento merged 2 commits intodevelopfrom
copilot/sub-pr-247

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 22, 2026

NamespacedKey.fromString() returns null for malformed keys, but the result was passed directly to Registry.MATERIAL.get() and Bukkit.getTag(), causing an NPE at runtime for any invalid config entry containing :.

Changes

  • BlockLimitsListener.loadLimits(): Added null check after NamespacedKey.fromString(); logs a warning and skips the entry if the key is invalid
nsKey = NamespacedKey.fromString(key.toLowerCase(Locale.ROOT));
if (nsKey == null) {
    Bukkit.getLogger().warning("Invalid namespaced key in config, skipping: " + key);
    continue;
}

💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

…id config keys

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Agent-Logs-Url: https://github.com/BentoBoxWorld/Limits/sessions/56d41e06-a992-4918-ab51-e628761ed89e
Copilot AI changed the title [WIP] [WIP] Apply changes based on feedback from PR #247 discussion Guard against NPE from NamespacedKey.fromString() returning null in loadLimits() Mar 22, 2026
Copilot AI requested a review from tastybento March 22, 2026 02:39
@tastybento tastybento marked this pull request as ready for review March 22, 2026 02:44
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@tastybento tastybento merged commit 74ab793 into develop Mar 22, 2026
2 of 3 checks passed
@tastybento tastybento deleted the copilot/sub-pr-247 branch March 22, 2026 02:49
tastybento added a commit that referenced this pull request Mar 23, 2026
* Fix sonarcloud criticals (#244)

* Add CLAUDE.md with build commands and architecture overview

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix #242: enforce shulker entity limit on Paper via ShulkerDuplicateEvent

On Paper servers, CreatureSpawnEvent fires for the new shulker *after* the
original shulker has already teleported away. If the original shulker
teleports outside the island bounding box, getNearbyEntities counts N-1
shulkers instead of N, so the limit check incorrectly allows duplication
past the configured limit.

Paper's ShulkerDuplicateEvent fires *before* the original shulker teleports
and before the duplicate is created, so the island entity count is accurate.
Register PaperShulkerLimitListener when Paper is detected at runtime;
fall back to the existing CreatureSpawnEvent handling on Spigot.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix CI compilation errors

- Change Paper API dependency from 1.21.8 to 1.20.4, which is the last
  version compiled for Java 17. Paper 1.20.6+ targets Java 21 (class
  version 65), which the compiler rejects under --release 17.
- Stage the remaining add_tags source files (IslandBlockCount,
  BlockLimitsListener, RecountCalculator, etc.) that Limits.java depends
  on; they were missing from the previous commit, causing NamespacedKey /
  Material type mismatches in CI.
- Fix @AfterEach (JUnit 5) -> @after (JUnit 4) in the three test files
  that have JUnit 4 imports; the annotation was unresolved in CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Incorporate log-limits-on-join setting from master

Add isLogLimitsOnJoin() config option (from master commit bdf41ea) so
that the verbose per-permission log lines can be silenced. Wraps each
addon.log() call in checkPerms/runNullCheckAndSet with the guard.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix SonarCloud CRITICAL issues: reduce cognitive complexity and duplicate literals

- Extract ISLAND_PLACEHOLDER constant in Limits.java (6 occurrences of "_island_")
- Extract UNKNOWN_PLAYER/NO_ISLAND/UNKNOWN_MATERIAL constants in OffsetCommand.java
- Extract handlePipelineResult() in CalcCommand to reduce cognitive complexity
- Extract logIfEnabled() and applyAmbiguousLimit() in JoinListener to reduce complexity
- Extract collectIslandGroupLimits(), applyGlobalGroupLimits(), updateGroupLimitsFromIbc(),
  checkGroupLimits() in EntityLimitListener to reduce atLimit() complexity from 23 to ~10
- Extract isGolemHead(), eraseGolemIfArmsMatch(), isWitherHead(), eraseWitherIfArmsMatch()
  in EntityLimitListener to reduce detectIronGolem/detectWither complexity
- Break Pipeliner<->RecountCalculator class cycle by replacing Pipeliner parameter in
  RecountCalculator.scanIsland() with functional interfaces (LongSupplier, Runnable, BooleanSupplier)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix BlockFormEvent handler to track material transitions for copper chest oxidation/waxing (#246)

* Initial plan

* Fix copper chest oxidation and waxing not updating block limit counts

When copper chests oxidize or are waxed with honeycomb, the BlockFormEvent
handler now properly handles the material transition by removing the old
block state count and adding the new block state count.

Added overloaded process(Block, BlockData, boolean) method to support
processing with block data different from the block's current data.

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Agent-Logs-Url: https://github.com/BentoBoxWorld/Limits/sessions/86aebdc8-0a0e-414d-a489-33caf8d9beb4

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>

* Update src/main/java/world/bentobox/limits/objects/IslandBlockCount.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/main/java/world/bentobox/limits/objects/IslandBlockCount.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix pom.xml build.version to match Release 1.27.2 (#251)

* Initial plan

* Fix build.version in pom.xml to match PR title (1.28.0 → 1.27.2)

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Agent-Logs-Url: https://github.com/BentoBoxWorld/Limits/sessions/7667d74f-edbf-43b7-ae30-538a7089f8e2

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>

* Guard against NPE from NamespacedKey.fromString() returning null in loadLimits() (#249)

* Initial plan

* Add null check for NamespacedKey.fromString() to prevent NPE on invalid config keys

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Agent-Logs-Url: https://github.com/BentoBoxWorld/Limits/sessions/56d41e06-a992-4918-ab51-e628761ed89e

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>

* Fix loadLimits() to reject non-block and uncountable materials (#250)

* Initial plan

* Fix loadLimits() to only accept block materials and skip DO_NOT_COUNT entries

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Agent-Logs-Url: https://github.com/BentoBoxWorld/Limits/sessions/5f78316a-24c1-42fc-81ba-d8cc8c6a52bb

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>

* Bump Java to 21 and Spigot target to 1.21.11 (#252)

* Initial plan

* Bump Java to 21, Spigot to 1.21.11, update Paper API and compiler plugin

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Agent-Logs-Url: https://github.com/BentoBoxWorld/Limits/sessions/511560f5-439c-478b-a893-e818934a00fe

* Fix CI: update workflow to use JDK 21 (Temurin) and bump action versions to v4

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Agent-Logs-Url: https://github.com/BentoBoxWorld/Limits/sessions/026bbbf3-4059-4e06-a02e-e18e52f9c749

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>

* Migrate JoinListenerTest from JUnit 4 + PowerMock to JUnit 5 + Mockito

Fixes merge conflict breakage where this test file retained JUnit 4 and
PowerMock imports/annotations that were removed in the JUnit 5 migration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Migrate from custom ServerMocks to MockBukkit

Replace the custom ServerMocks utility with MockBukkit, aligning with
the standardized test infrastructure used across the BentoBox ecosystem.

- Add MockBukkit v1.21-SNAPSHOT dependency (via jitpack.io)
- Switch from spigot-api to paper-api (required by MockBukkit)
- Replace ServerMocks.newServer()/unsetBukkitServer() with
  MockBukkit.mock()/unmock() in all 12 test files
- Remove manual server stubs that MockBukkit handles natively
  (scheduler, plugin manager, item factory, unsafe values)
- Delete ServerMocks.java and the mocks/ package
- Add compiler --add-exports args and -XX:+EnableDynamicAgentLoading

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants