Code smell candidate?
Answered
Today I stumbled upon this code:
if (string != null && string.chatAt(0) == 'x') {
...
}
Which will throw an index out of bound exception when string is empty.
The intention was to write this instead:
if (string != null && string.startsWith("x")) {
...
}
IDEA didn't warn that the code may throw an exception or suggest rewriting it using startsWith. Potential candidate?
Just my fiddy cents.
Please sign in to leave a comment.
Created feature request for that: https://youtrack.jetbrains.com/issue/IDEA-273681
But it is shelved for now. See this comment: