Skip to content

UnnecessarySubstring is unsafe; should be deprecated #562

Closed

Description

@bernhof

With reference to old issue from sourceforge: https://sourceforge.net/p/codenarc/bugs/98/

UnnecessarySubstring warns about all uses of String.substring, but replacing with range fails if string's length is 1.

String input = "/"
input.substring(1) // works
input[1..-1] // fails
input.substring(0, input.size() - 1) // works
input[0..-2] // fails

https://groovyconsole.appspot.com/script/5161322018766848

Activity

  1. chrismair commented on Oct 7, 2020

    @chrismair
    Contributor

    Okay, so I guess we should consider removing/disabling the check for substring(int, int).

  2. bernhof commented on Oct 7, 2020

    @bernhof
    Author

    Yes and for substring(int), too.

  3. added a commit that references this issue on Dec 30, 2020
  4. chrismair commented on Dec 30, 2020

    @chrismair
    Contributor

    I have deprecated the UnnecessarySubstring rule.

  5. added a commit that references this issue on Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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