manifold-ij
manifold-ij copied to clipboard
[Bug] Sonarlint complains about unused assignment/local variables when using string interpolation
In this code snippet:
default String getTemplateFileName(HttpServletRequest request, Model model) {
URI baseUri = getBaseUri();
String templateFileName = this.getClass().getSimpleName() + ".ftl";
String canonicalFileName = getResource(templateFileName)
.map(baseUri::relativize)
.map(URI::getPath)
.orElse(COMPONENT_TEMPLATE_PREFIX + "content/error/Status500.ftl");
log.info("Template name: $canonicalFileName");
return "/$canonicalFileName";
}
The canonicalFileName is used in 2 places, however it is ONLY used in string interpolation. SonarLint doesn't understand how manifold added string interpolation, so it is giving a false positive that canonicalFileName is an unused local variable. Because of this, it also erroneously detects that the assignment to that variable is unused.
I don't know if I should file this bug here or on the SonarLint side. I think that the solution might be a combination of both.
As an IntelliJ plugin the invalid errors from Sonarlint may be suppressed from the manifold plugin. If Sonarlint is a JDK tool, not much can be done on my part if it isn't using the javac AST for analysis, which is fully formed with interpolation from manifold. I'll have a deeper look at sonarlist at some point.
As an IntelliJ plugin the invalid errors from Sonarlint may be suppressed from the manifold plugin.
Well, good thing that SonarLint is a plugin then: https://plugins.jetbrains.com/plugin/7973-sonarlint