Skip to content

Comments

fix(java): Fix EnumSetSerializer for enums with overriding methods#3315

Merged
chaokunyang merged 1 commit intoapache:mainfrom
NotLebedev:3306-enumset
Feb 9, 2026
Merged

fix(java): Fix EnumSetSerializer for enums with overriding methods#3315
chaokunyang merged 1 commit intoapache:mainfrom
NotLebedev:3306-enumset

Conversation

@NotLebedev
Copy link
Contributor

@NotLebedev NotLebedev commented Feb 9, 2026

Why?

Fix EnumSetSerializers for enums that have overriding methods in vairants:

  enum TestEnumWithMethods {
    A {
      @Override
      public void foo() {
          System.out.println("A");
      }
    },
    B,
    C {
      @Override
      public void foo() {
      }
    },
    D;

    public void foo() {
        System.out.println("default");
    }
  }

What does this PR do?

EnumSetSerializer now correctly unwraps types of variants that extend base enum type. Doing it this way instead of writing class of variant and unwrapping it in read prevents writing additional classes for enum variants.

Related issues

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

This PR changes class of contained enum that EnumSetSerializer writes. Instead of writing class of enum variant if this variant extends base enum class it always writes class of base enum. This however does not break any existing code since previously EnumSets of classes with overriding methods could not be deserialized at all

Benchmark

Copy link
Collaborator

@chaokunyang chaokunyang left a comment

Choose a reason for hiding this comment

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

LGTM

@chaokunyang chaokunyang merged commit 65cd46f into apache:main Feb 9, 2026
56 checks passed
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.

[Java] Incorrect serialization of EnumSet if enum has variants with overriding methods

2 participants