Skip to content

Avoid NPE when clearing a region flag - #2307

Open
HP-network wants to merge 1 commit into
EngineHub:version/7.0.xfrom
HP-network:codex/fix-region-flag-none-feedback
Open

HP-network wants to merge 1 commit into
EngineHub:version/7.0.xfrom
HP-network:codex/fix-region-flag-none-feedback

Conversation

@HP-network

Copy link
Copy Markdown

When a state flag is set to none, parsing intentionally returns null after clearing the flag. The command feedback path called toString() on that value, so the command completed but logged an NPE.

Keep the existing normalized output for non-null values and report none for the clear operation.

Fixes #2305

Tested with ./gradlew :worldguard-core:test.

@me4502 me4502 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! :)

The original issue misconstrued the problem a bit, this isn't the recommended nor documented way to unset flags on a region, but worked due to some legacy parsing code that happened to line up with command handling. As far as I can tell, some LLMs hallucinated none as the correct keyword to unset a flag, which led to people starting to use the wrong command.

IMO the goal here should be to prevent it from actually erroring when using this alternate command, rather than changing any behaviour beyond that point. Currently this PR uses different messaging when setting a flag to the none value compared to unsetting a flag, and ideally the none value should be treated the same as the intended command to unset a flag. I've left a comment on a way that I feel would fix that side of things :)

try {
value = setFlag(existing, foundFlag, sender, value).toString();
Object parsedValue = setFlag(existing, foundFlag, sender, value);
value = parsedValue == null ? "none" : parsedValue.toString();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is treating it like the value "none" is being set on the region, whereas the flag is being removed. This should ideally trigger a message such as the one on like 621 (https://github.com/EngineHub/WorldGuard/pull/2307/changes#diff-cd6887d878ad3f9bebfe64edf07696bb25bb4f33a91877bf814acefd800243caL621). So maybe rather than just subbing in the word "none", setting value to null so that it can be better handled with proper messaging later on.

@HP-network

HP-network commented Sep 24, 2026 •

Copy link
Copy Markdown
Author

Thanks, that distinction makes sense. none is taking the clear/remove path, so it should keep the existing unset feedback rather than be treated as a value to set. I'll adjust the command handling accordingly and rerun the core tests.

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.

NullPointerException when setting flag to "none" in RegionCommands.setFlag

2 participants