-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: Scala
Background
While Integrating with the scala mongo driver we discovered https://github.com/mongodb/mongo-java-driver/blob/r4.3.3/driver-scala/src/main/scala/org/mongodb/scala/Observable.scala#L366-L376]
the .head method hides a null underneath, as this is not documented nor is it defended against codebases can become vulnerable to null pointer exceptions or invalid responses in an API service, the fallback is to make use of .toFutureOption however as the risk isn't documented teams may only discover this when they hit it.
If this is undefended against the code above continues to pass, Until someone tries to access something in the desired object.
Solutions
1. ** Document the behaviour and offer more guidance in handling
2. Throw NoSuchElementException instead of null.asInstanceOf
3. Create a custom Exception to indicate what the null pointer means (the query returned nothing.)