I propose to add in S6611 why NoSuchElementException is better than NullPointerException

I propose to add an explanation to the Compliant solution of S6611 “Map values should be accessed safely” why NoSuchElementException is better than NullPointerException.

Hi,

Welcome to the community!

What explanation do you propose?

 
Ann

Personally, I see the only advantage in the fact that the error message contains the key for which the value was not obtained. Perhaps you meant something else.

Hi,

I suspect we’re not quite connecting on meaning.

Do you mean that you suggest we come up with and add an explanation to the compliant solution?

I guess you’re saying the issue message isn’t helpful enough?

 
Thx,
Ann

Yes, that’s right. I suggest adding a rationale - why you are suggesting replacing NullPointerException with NoSuchElementException.

1 Like

Hi,

Thanks for the clarification. Just one more question: what’s your version of SonarQube? You can find it in the page footer if you’re not sure.

 
Thx,
Ann

version is Community Edition Version 10.4 (build 87286)

1 Like