Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix type parameters not being passed to fallback property codec #1765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GliczDev wants to merge 1 commit into mongodb:main
base: main
Choose a base branch
Loading
from GliczDev:patch-1

Conversation

Copy link

@GliczDev GliczDev commented Jul 11, 2025

For some reason, type parameters weren't passed to fallback property codec, which caused an exception when trying to access them. Now, this issue is fixed.

@GliczDev GliczDev requested a review from a team as a code owner July 11, 2025 00:59
@GliczDev GliczDev requested review from NathanQingyangXu and removed request for a team July 11, 2025 00:59
Copy link
Contributor

@rozza , I am not sure about the validity of the code changes proposed. For one thing, it breaks 6 unit testing cases; secondly it seems FallbackPropertyCodecProvider opted for calling CodecRegistry#get(Type) intentionally, for the reason that the other get(Type, List<Type>() might not be overridden, thus defeating the purpose of fallback as the last resort.
How do you think?

Copy link
Member

rozza commented Jul 21, 2025

@GliczDev looks like this PR needs some tests and as @NathanQingyangXu mentioned this does appear to break some existing test cases.

To run the bson tests and checks run ./gradlew bson:check from the shell.

Copy link
Member

@rozza rozza left a comment
edited
Loading

Choose a reason for hiding this comment

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

I added a couple of requested changes - to support java 8+ and to ensure that types are only provided if the list is not empty.

The LookupCountingCodecRegistry implementation in tests will need to implement <T> Codec<T> get(Class<T> clazz, List<Type> typeArguments) inorder not to throw an exception.

eg:

@Override
public <T> Codec<T> get(final Class<T> clazz, final List<Type> typeArguments) {
 incrementCount(clazz);
 for (CodecProvider provider : codecProviders) {
 Codec<T> codec = provider.get(clazz, typeArguments, this);
 if (codec != null) {
 return codec;
 }
 }
 return null;
}

It would also be good to add a regression test where this code path is used.

NathanQingyangXu reacted with thumbs up emoji NathanQingyangXu reacted with heart emoji
import org.bson.codecs.Codec;
import org.bson.codecs.configuration.CodecRegistry;

import java.lang.reflect.Type;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import java.lang.reflect.Type;
import java.lang.reflect.Type;
import java.util.List;
import java.util.stream.Collectors;

return (Codec<S>) pojoCodec;
}
return codecRegistry.get(type.getType());
return codecRegistry.get(type.getType(), type.getTypeParameters().stream().<Type>map(TypeWithTypeParameters::getType).toList());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
returncodecRegistry.get(type.getType(), type.getTypeParameters().stream().<Type>map(TypeWithTypeParameters::getType).toList());
List<Type> types = type.getTypeParameters().stream().<Type>map(TypeWithTypeParameters::getType).collect(Collectors.toList());
if (!types.isEmpty()) {
return codecRegistry.get(type.getType(), types);
}
return codecRegistry.get(type.getType());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@rozza rozza rozza requested changes

@NathanQingyangXu NathanQingyangXu Awaiting requested review from NathanQingyangXu NathanQingyangXu is a code owner automatically assigned from mongodb/dbx-java

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /