Repository navigation
Don't generate getters for inaccessible getters made accessible - #377
Merged
Merged
Conversation
…ible With a class-level `@JsonInclude(NON_DEFAULT)`, databind makes the getters accessible (to read the default bean's values) before Blackbird sees them. `unreflect` then skips its access checks, so an inherited package-private getter from another package got a generated getter that `LambdaMetafactory` rejects, failing every serialization of the bean. Unreflect a copy that isn't accessible, as the deserializer side already does; the helper moves to `ReflectionHack` for both.
…s one `getDeclaredMethod` picks by name and parameters only, so for a bridge method (or the method it bridges to) it could return the other one, with a different return type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With a class-level
@JsonInclude(NON_DEFAULT), databind'sPropertyBuildermakes each getter accessible (to read the default bean's values) before Blackbird'schangePropertiessees it.lookup.unreflectskips its access checks for an accessibleMethod, so a getter the generated accessor can't call is no longer refused there, andcanLinkAccessorpasses too.For a bean inheriting a package-private
@JsonPropertygetter from a superclass in another package,LambdaMetafactorythen rejects the handle, and every serialization of the bean fails (plain databind writes it fine):RuntimeException: LambdaConversionException: MethodHandle(...)int is not direct or cannot be crackedInvalidDefinitionException: IllegalAccessException: member is private to packageThis also happens with 2.22.4, so it isn't a regression from #366. Without
NON_DEFAULT, the getter isn't accessible yet, and #366's existing fallback works.Fix
Unreflect a copy of the getter that isn't accessible, as the deserializer side already does for setters. The helper moves from
BBDeserializerModifiertoReflectionHack.withoutAccessOverrideso both modifiers use it. The serializer also catches the same exceptions as the deserializer (NoSuchMethodException,SecurityException).Tests
New
TestInaccessibleGetterTypes.testInheritedGetterMadeAccessible: output matches vanilla, the hidden getter is left toBeanPropertyWriter, and the bean's own getter is still optimized. It fails without the fix. The Blackbird suite passes locally on JDK 11, 17 and 21; JDK 8 wasn't available locally.