Skip to content

Modernize instanceof checks, switch expressions, and error handling - #3635

Open
MattBDev wants to merge 3 commits into
v3from
refactor/v3/modern-java
Open

Modernize instanceof checks, switch expressions, and error handling#3635
MattBDev wants to merge 3 commits into
v3from
refactor/v3/modern-java

Conversation

@MattBDev

@MattBDev MattBDev commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Consolidate instanceof checks to pattern-variable form and convert legacy switch statements to arrow-form switch expressions across the codebase (NBT streams, block/direction/entity registries, expression compiler, YAML, math utils, etc.)

  • Improve error message formatting and use try-with-resources for Closer in BukkitImplLoader

  • Errorprone library was added to libs.versions.toml for future work when catching up to upstream. Included it just in case we choose to adopt it too.

@MattBDev
MattBDev requested a review from a team as a code owner August 25, 2026 20:00
return switch (actor) {
case com.sk89q.worldedit.entity.Player player -> adapt(player);
case BukkitBlockCommandSender bukkitBlockCommandSender -> bukkitBlockCommandSender.getSender();
case null, default -> ((BukkitCommandSender) actor).getSender();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this may result in an NPE. I just want a second opinion on this before I go and fix it before the PR is approved and merged.

@SirYwell

Copy link
Copy Markdown
Member
  1. I feel like we shouldn't touch WE classes/code. If they applied similar changes, cherry-picking them might make more sense.
  2. So errorprone is included because WE uses it? I'm not exactly a fan of it, due to its tight integration with internal javac apis.
  3. The code style seems rather inconsistent (e.g., usage of final in instanceof pattern matching, that said I'm not a fan of noisy final usage at all).
  4. It might make more sense to replace Closer usage with try-with-resources completely. AFAIK it's a pre TWR artifact to make dealing with closables easier.

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