[JAVA-4313] Observable head should not return null Created: 26/Sep/21  Updated: 27/Oct/23  Resolved: 28/Sep/21

Status: Closed
Project: Java Driver
Component/s: Scala
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Scott Rice Assignee: Ross Lawley
Resolution: Works as Designed Votes: 0
Labels: external-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by JAVA-4322 Observable<T> toFuture() implicit ret... Backlog

 Description   

null shouldn't be returned by a Scala library. None should be returned instead. So, Observable.head could be changed to this:

// Some comments here
  def head(): Future[T] = {
    headOption().map {
      case Some(result) => result
      case None         => None.asInstanceOf[T] 
    }(Helpers.DirectExecutionContext)
  }



 Comments   
Comment by Ross Lawley [ 28/Sep/21 ]

Unfortunately, null is unavoidable here.

Comment by Scott Rice [ 26/Sep/21 ]

On second thought, None is not a valid value of most types of T. So, my proposed solution isn't a good one.

Using null here may be unavoidable.

Generated at Thu Feb 08 09:01:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.