Menu

#98 rule to replace substring is unsafe. should be deprecated

open
nobody
None
5
2013-02-16
2011-10-17
No

Reported by @evgeny_goldin on twitter:

UnnecessarySubstring: s.substring( j ) != s[ j .. -1 ], substring gets empty String if j = s.size(), s[ j .. -1 ] fails (#groovy)

I followed this rule and switched to [ j .. -1 ] which introduced a number of bugs in those edge cases. Back to safer substring()

@tim_yates says:
"apart from negative numbers return all the string, and numbers greater than its length return ''

I'm not 100% what the problem is. Maybe the rule is just a bad idea to begin with.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.