Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

UnnecessaryStringNonEmpty false positive? #58

Open
nfsantos opened this issue Jun 19, 2017 · 0 comments
Open

UnnecessaryStringNonEmpty false positive? #58

nfsantos opened this issue Jun 19, 2017 · 0 comments

Comments

@nfsantos
Copy link

nfsantos commented Jun 19, 2017

With version 0.1.17, I get a false positive with the following code:

def test1(s: StringBuilder): Boolean = {
    if (s != null) {
      val trimmed = s.toString.trim
      trimmed.nonEmpty
    } else {
      false
    }
  }
Warning:(123, 15) [UnnecessaryStringNonEmpty] This string will never be empty.
      trimmed.nonEmpty

If I remove the intermediate variable trimmed, the false positive disappears:

  def test2(s: StringBuilder): Boolean = {
    if (s != null) {
      s.toString.trim.nonEmpty
    } else {
      false
    }
  }

It is also not reported if we replace StringBuilder by String as the argument:

  def test3(s: String): Boolean = {
    if (s != null) {
      val trimmed = s.trim
      trimmed.nonEmpty
    } else {
      false
    }
  }
@nfsantos nfsantos changed the title Wrong UnnecessaryStringNonEmpty warning UnnecessaryStringNonEmpty false positive? Jun 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant