string.Intern does have a side-effect but sonarqube says it doesn't

csharp

(dktue) #1
  • Version 7.0 (build 36138)

The following code is marked as a bug from sonarqube:

foreach (string str in stringsToIntern) string.Intern(str);

It says “Use the return value of method ‘Intern’, which has no side effect.”. Actually, string.Intern does have a side-effect. It actually interns the string if it’s not interned already. Hence, this should not be marked as a bug.


(Andrei Epure) #2

Thanks @dktue I’ve opened issue 2382 to track this FP