You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
andrei-epure-sonarsource
changed the title
S2201 FP: issue is raised for string.Intern which has side effect
Fix S2201: FP for string.Intern which has side effect
Apr 17, 2019
Looking at the documentation for string.Intern, the method does not seem to have any side effect.
Only the string returned by the method will be interned, the string given as parameter will not be have been interned, so its reference might still be different than the interned one.
If the string does not exist, a reference to str is added to the intern pool, then that reference is returned.
Although I don't see why one would not use the return value that holds the reference to the interned string, since it has a side effect, we can definitely add an exception for this rule.
Description
string.Intern
has a side-effect: it actually interns the string if it’s not interned already. Hence, this should not be marked as a bug by S2201.Repro steps
Add
string.Intern("foo");
inside ReturnValueIgnored.cs and run theReturnValueIgnored
UT.Expected behavior
Should not raise an issue.
Actual behavior
Raises an issue
'Use the return value of method 'Intern', which has no side effect.'
Related information
Originally reported on community.sonarsource.com
The text was updated successfully, but these errors were encountered: