Thanks to visit codestin.com
Credit goes to github.com

Skip to content

String diff fails with NPE when one of the Strings is null #6764

@nightscape

Description

@nightscape

When comparing a String with null the Differ fails with a NullPointerException.
Minimal repro:

import zio.Scope
import zio.test._
object StringDiffTest extends ZIOSpecDefault {
  override def spec: ZSpec[TestEnvironment with Scope, Any] =
    test("String diffing fails") {
      assertTrue("" == null)
    }
}

The reason is that DiffInstances#stringDiff tries to split the Strings at newlines, which won't work for null.

I know using null is not a best practice, but sometimes one doesn't have a choice when interacting with Java APIs...
I would propose adding a special case for null at the beginning of the diffing, but I'm open to other suggestions.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions