[SERVER-68705] Refactor BSONElement API to avoid unsafe implicit type conversion Created: 10/Aug/22  Updated: 05/Dec/22

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Dan Larkin-York Assignee: Backlog - Storage Execution Team
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-26148 Commands should convert integers from... Backlog
is related to SERVER-68309 Investigate for unsafe narrowing conv... Closed
Assigned Teams:
Storage Execution
Participants:

 Description   

At the moment we have a mix of different methods which can perform unsafe implicit type conversions, without being very clear to the user about what's happening from simple call-site inspection. The most concerning cases are numberInt/numberLong and safeNumberInt/safeNumberLong. These types will coerce a BSONElement of any numeric type into the target type. In the case of numberInt/numberLong, this can have undefined behavior. In the case of safeNumberInt/safeNumberLong, the behavior is well-defined, but still often unexpected.

We also have coerce methods for various output types which will do the same thing under the hood, but are more explicit about what's happening.

We should investigate improvements to these APIs to make the default, intuitive methods safer.


Generated at Thu Feb 08 06:11:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.