Please provide
- Operating system: MacOS
- SonarLint plugin version: 9.0.0.75308
- Programming language you’re coding in: Kotlin
- Is connected mode used: No
We are getting trouble complying with this lint.
view.viewTreeObserver
.addOnGlobalLayoutListener(object : OnGlobalLayoutListener {
override fun onGlobalLayout() {
// Remove this listener to avoid memory leak
adView.viewTreeObserver.removeOnGlobalLayoutListener(this)
// Add padding to avoid banner ad overlapping RecyclerView
recyclerView.setPadding(recyclerOrigLeftPadding, 0, 0, adsContainer.height)
}
})
The lint is triggering kotlin:S6516, which can be solve by changing the code to this
view.viewTreeObserver
.addOnGlobalLayoutListener {
// Remove this listener to avoid memory leak
adView.viewTreeObserver.removeOnGlobalLayoutListener(this)
// Add padding to avoid banner ad overlapping RecyclerView
recyclerView.setPadding(recyclerOrigLeftPadding, 0, 0, adsContainer.height)
}
However by doing so, the this
parameter is no longer valid and will not compile as it can no longer get the instance of this single function interface.