Skip to content

OptionIdOps.some should handle nulls correctly #4789

@Ivan091

Description

@Ivan091

Considering #871,
I’ve been really surprised to find that OptionIdOps.some actually allows constructing Some(null) with no issues.
You can write:

val s: String = null
val o = s.some // is Some(null)

However, should we allow users to do that?
It’s a really bad practice to construct Some(null), as this defeats the purpose of Option and breaks a lot of code.
People use Cats as an example for their own projects, and, I think, we should not promote allowing the construction of Some(null).

I propose that we deprecate OptionIdOps.some and introduce OptionIdOps.option as a safe alternative:

def option: Option[A] = Option(a)

Alternatively, we could roll back OptionIdOps.some to its original null-safe state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions