Skip to content

Conversation

mjd507
Copy link
Contributor

@mjd507 mjd507 commented Jul 19, 2025

Related to: #10083

@@ -611,49 +615,47 @@ public <S> S read(Class<S> clazz, Bson source) {
}

private MessageWrapper readAsMessageWrapper(Bson source) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can not make this method return nullable, the underlying spring-data-mongodb does not allow to return null.
so I assert the source param never null?

@@ -144,6 +148,7 @@ protected MessageBuilderFactory getMessageBuilderFactory() {
@Override
public void afterPropertiesSet() {
if (this.mongoTemplate == null) {
Objects.requireNonNull(this.mongoDbFactory);
Copy link
Member

Choose a reason for hiding this comment

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

DITTO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

below MappingMongoConverter and MongoTemplate both use this, so I leave it here.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. Then NullAway.Init on this connectionFactory property ?

Copy link
Member

Choose a reason for hiding this comment

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

Or Assert.notNull().
This method is called only once, so having a check is OK.
We use Objects.requireNonNull only if we deliberately know that it is not null.
Probably one day I’ll revise them all into a NullAway suppressions since I’m very picky for performance 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mongoDbFactory can be null, when we give a mongoTemplate via ctor

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or Assert.notNull(). This method is called only once, so having a check is OK. We use Objects.requireNonNull only if we deliberately know that it is not null. Probably one day I’ll revise them all into a NullAway suppressions since I’m very picky for performance 😁

ok

new Update().inc(SEQUENCE, 1L),
FindAndModifyOptions.options().returnNew(true).upsert(true),
Map.class, this.collectionName);
Objects.requireNonNull(result);
Copy link
Member

Choose a reason for hiding this comment

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

This looks redundant since you use another one in the next operator.
We need to think to get rid off of this at all if we are sure it is never null.
If this is a critical execution path, it would be better to avoid as much as possible extra calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppress it with NullAway.

Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Pulling this locally for final review and possible clean up & merge.

Thank you again for so many great contributions!

@artembilan
Copy link
Member

Merged as: fb12c05

@artembilan artembilan closed this Jul 21, 2025
@mjd507 mjd507 deleted the jspecify-mongodb branch July 21, 2025 16:22
artembilan added a commit that referenced this pull request Jul 21, 2025
@artembilan
Copy link
Member

Here is some clean up after your change: a3476d2.

Pay attention to the fix in all those components where we have a choice between template and connection factory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants