Skip to content

fix: replace PatternType.getByIdentifier() with PatternTypeProvider#6553

Open
1wairesd wants to merge 1 commit into
EssentialsX:2.xfrom
1wairesd:2.x
Open

fix: replace PatternType.getByIdentifier() with PatternTypeProvider#6553
1wairesd wants to merge 1 commit into
EssentialsX:2.xfrom
1wairesd:2.x

Conversation

@1wairesd
Copy link
Copy Markdown
Contributor

PatternType.getByIdentifier() causes IncompatibleClassChangeError on 1.19.4 due to a mismatch between Methodref and InterfaceMethodref bytecode constants when compiled against a newer API.

Introduce PatternTypeProvider with two implementations:

  • LegacyPatternTypeProvider: iterates PatternType.values() for 1.19.4 and older where PatternType is still an enum
  • ModernPatternTypeProvider: uses Registry.BANNER_PATTERN for 1.20.5+

Update MetaItemStack.addBannerMeta to resolve PatternType through the provider instead of calling the deprecated static method directly.

You need to select a pull request template!

If you're adding a new feature, copy and paste the following parameter at the end of the URL:
?template=new-feature.md

If you're fixing a bug, copy and paste the following parameter at the end of the URL:
?template=bug-fix.md

For more information about contributing to EssentialsX, see CONTRIBUTING.md:
https://github.com/EssentialsX/Essentials/blob/2.x/CONTRIBUTING.md

PatternType.getByIdentifier() causes IncompatibleClassChangeError on
1.19.4 due to a mismatch between Methodref and InterfaceMethodref
bytecode constants when compiled against a newer API.

Introduce PatternTypeProvider with two implementations:
- LegacyPatternTypeProvider: iterates PatternType.values() for 1.19.4
  and older where PatternType is still an enum
- ModernPatternTypeProvider: uses Registry.BANNER_PATTERN for 1.20.5+

Update MetaItemStack.addBannerMeta to resolve PatternType through the
provider instead of calling the deprecated static method directly.
@mbax
Copy link
Copy Markdown
Member

mbax commented May 31, 2026

@1wairesd
Copy link
Copy Markdown
Contributor Author

1wairesd commented Jun 1, 2026

Information
This PR fixes #6553.

Details
Proposed fix: PatternType.getByIdentifier() is a static method on an interface (Keyed), but when EssentialsX is compiled against a newer Bukkit API and run on 1.19.4, the JVM throws IncompatibleClassChangeError because the bytecode expects a Methodref constant but finds an InterfaceMethodref (or vice-versa). The try/catch around the call only catches Exception, not Error, so the crash propagates.

The fix introduces a PatternTypeProvider interface with two implementations selected at runtime via the existing provider system:

LegacyPatternTypeProvider (weight 0) — iterates PatternType.values() and compares identifiers; works on 1.19.4 and older where PatternType is still an enum.
ModernPatternTypeProvider (weight 1) — uses Registry.BANNER_PATTERN.get(NamespacedKey.minecraft(...)) for 1.20.5+ where PatternType became a Registry-backed Keyed type.
MetaItemStack.addBannerMeta is updated to resolve PatternType through the provider instead of calling the deprecated static method directly.

Environments tested:

OS: Windows 10, Ubuntu 22.04

Java version: 21

Most recent Paper version (1.19.4, git-Paper-550)
CraftBukkit/Spigot/Paper 1.12.2
CraftBukkit 1.8.8
Demonstration:

Before (1.19.4):

[ERROR]: Command kit failed: java.lang.IncompatibleClassChangeError: Method
'org.bukkit.block.banner.PatternType
org.bukkit.block.banner.PatternType.getByIdentifier(java.lang.String)'
must be Methodref constant
at com.earth2me.essentials.MetaItemStack.addBannerMeta(MetaItemStack.java:745)
After: /kit with banner items works correctly on 1.19.4.

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