Skip to content

Preserve the Class-based TypeHandlerRegistry registration descriptor - #3840

Merged
hazendaz merged 5 commits into
mybatis:masterfrom
wozhenbang2004:fix/type-handler-class-compat
Nov 1, 2026
Merged

hazendaz merged 5 commits into
mybatis:masterfrom
wozhenbang2004:fix/type-handler-class-compat

Conversation

@wozhenbang2004

Copy link
Copy Markdown
Contributor

Related to #3837.

This adds back the three-argument register(Class, JdbcType, TypeHandler) entry point as a small bridge to the Type overload. It preserves the JVM descriptor used by previously compiled clients without changing Type-based handler resolution.

I understand #3379 deliberately introduced breaking changes. Would keeping this particular entry point be acceptable? A client compiled against 3.5.19 throws NoSuchMethodError on 3.6.0 and runs unchanged with this bridge.

Validation on JDK 17:

  • The 12 existing registry tests and 3 new tests pass. Without the bridge, the new exact-descriptor test fails.
  • The same old client was run against 3.5.19, 3.6.0 and the patched registry.
  • Checked Class/Type overloads, wildcard and parameterized types, and null inputs against both APIs.

These were focused checks; I haven't run the full Maven build, formatter, database integrations or Flowable startup.

Delegate the Class overload to Type registration and cover the legacy
method descriptor and registration paths.

Related to mybatis#3837.
@coveralls

coveralls commented Oct 30, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 87.469% (+0.02%) from 87.45% — wozhenbang2004:fix/type-handler-class-compat into mybatis:master

@hazendaz

Copy link
Copy Markdown
Member

@harawata Thoughts on this? I think following the original work, expectation is that it should be labeled as deprecated if accepted.

@hazendaz

Copy link
Copy Markdown
Member

@wozhenbang2004 I think its feasible to do so, need @harawata to chime in. I do think it needs to be marked deprecated like some of the others were to be consistent and drive consumers to the new one.

Direct callers to Type-based registration and replace deprecated lookup
assertions with identity checks on freshly registered handler instances.
@wozhenbang2004

Copy link
Copy Markdown
Contributor Author

Thanks, added the deprecation annotation and a Javadoc link to the Type overload. The focused tests and the unchanged 3.5.19-compiled client still pass.

@hazendaz

Copy link
Copy Markdown
Member

@wozhenbang2004 Thanks, lets give @harawata some time to see this. Appreciate quick response.

nullTypeRegistry.register((Class<?>) null, null, nullTypeHandler);
assertTrue(nullTypeRegistry.getTypeHandlers().stream().anyMatch(registered -> registered == nullTypeHandler));
}

void shouldKeepTypeRegistrationOverload() {
Type javaType = new TypeReference<List<String>>() {
}.getRawType();
TypeHandler<?> handler = new ObjectTypeHandler();
@harawata

Copy link
Copy Markdown
Member

Thank you for the PR, @wozhenbang2004 !
And thank you @hazendaz for the review!

I just took a quick look and...

  • I am OK with resurrecting methods with Class argument.
  • I am not OK with resurrecting methods with TypeReference argument. Those methods weren't doing anything meaningful, so no one actually used them I believe [1].
  • I prefer not to resurrect methods with String argument, but if you think it's necessary, I am OK with it.

If you need me to add a line comment on each method for clarity, please let me know and I will work on it later.

Note that, even if we resurrect those methods, it does not guarantee the same behavior (there were inconsistencies between those methods with Class argument).

[1] I actually planned to move TypeReference to test package, but forgot it apparently.


By the way, in the constructor, some of the lines registering the built-in type handler may need explicit casting (e.g. register((Type)String.class, ....) to avoid referencing deprecated method.

@wozhenbang2004

wozhenbang2004 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @harawata, the scope here is just the three-argument Class bridge; no TypeReference or String overloads are being restored. Added explicit Type casts to all 27 built-in registrations in the constructor in c244402, so they call the Type overload directly. The compatibility tests still deliberately exercise the deprecated Class entry point. The new CI workflows are awaiting maintainer approval.

@hazendaz hazendaz self-assigned this Nov 1, 2026
@hazendaz
hazendaz merged commit cf09c5e into mybatis:master Nov 1, 2026
7 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.

5 participants