There is a special case in our code where we need to call setText with getText of the same TextView. SonarLint warn this with kotlin:S1656, to suppress it we use @SuppressWarnings annotation but it does not work. It started showing an error to the IDE and the warning from SonarLint still there. //NOSONAR is not working as well
SonarLint: Suppress specific line warning in Android Studio
2.1k Views Asked by Bitwise DEVS At
2
There are 2 best solutions below
2
On
I found the docs for the issue to confirm its the right number: https://rules.sonarsource.com/kotlin/RSPEC-1656
Also read the source at https://github.com/SonarSource/sonarlint-intellij but not much help.
It seems like "// NOSONAR" is what you want (I know you said you tried it, but did you have the space? And have it at the end of the line?)
htmlTextView.text = htmlTextView.text // NOSONAR
Just a guess here, but you could also try:
@SuppressWarnings("RSPEC:S1656")
lastly to check suppress is working you can ignore everything:
@SuppressWarnings("all")
htmlTextView.text = htmlTextView.text
Big discussion here: Turning Sonar off for certain code
This article also gives you options to choose from: https://docs.codescan.io/hc/en-us/articles/360012109711-Ignoring-violations



Can you put the
SuppressWarningsannotation before your method?I also wonder that if
htmlTextView.invalidate()would work for you.UPDATE:
SuppressWarningsannotation is also available forLOCAL_VARIABLEbut I think the problem is more complicated in kotlin code.If you examine the byte code of these lines below, you can see that some.num = ... is some.setNum(...) in byte code.
Sonar plugin's code analyser may not handle this kind of kotlin specific codes.