Template for a good new topic, formatted with Markdown:
- ALM used: GitHub
- CI system used: GH Actions
- Scanner command used when applicable: sonarsource/sonarcloud-github-action@v5.0.0
- Languages of the repository: go
Hi,
I’m encountering a problem in one of my repositories. For some unknown reason, the Sonar scanner suddenly starts throwing a StackOverflowError, despite no code changes being introduced.
I’ve tried running the scanner in debug mode, but unfortunately there’s no additional information provided.
I’ve also reviewed all const
declarations and couldn’t find any signs of circular dependencies.
The code itself is compiling and passing tests successfully with Go 1.22, 1.23, and 1.24 — no issues at build time.
Stack trace is provided below.
Thanks in advance for any support!
ERROR: Error during SonarScanner execution
java.lang.StackOverflowError
at org.sonar.go.utils.ConstantResolution.resolveIdentifierAsStringConstant(ConstantResolution.java:82)
at org.sonar.go.utils.ConstantResolution.resolveAsPartialStringConstant(ConstantResolution.java:76)
at java.base/java.util.Optional.map(Optional.java:260)
at org.sonar.go.utils.ConstantResolution.resolveIdentifierAsStringConstant(ConstantResolution.java:87)
at org.sonar.go.utils.ConstantResolution.resolveAsPartialStringConstant(ConstantResolution.java:76)
at java.base/java.util.Optional.map(Optional.java:260)
...
at org.sonar.go.utils.ConstantResolution.resolveIdentifierAsStringConstant(ConstantResolution.java:87)
at org.sonar.go.utils.ConstantResolution.resolveAsPartialStringConstant(ConstantResolution.java:76)
at java.base/java.util.Optional.map(Optional.java:260)
at org.sonar.go.utils.ConstantResolution.resolveIdentifierAsStringConstant(ConstantResolution.java:87)
ERROR:
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
Hello @adam-sowinski_lyvecl and welcome to community!
As you are using Sonarqube Cloud, you get automatically the latest update of our analyzers.
We are in ongoing effort on our Go analyzer and a new version was released very recently, which explain why you are facing an issue despite any changes on your side.
We have improved our way of resolving variables to increase our rules precision, but it seems we have missed a specific use case which is leading to this issue.
Is it possible for you to provide more details about the analyzed code? A minimal reproducer would works the best. With the debug log of the scanner enabled by adding environment variable SONAR_SCANNER_OPTS: -X
, it should allow you to see on which file the error happened.
Thanks and sorry for the inconvenience.
Best,
Rudy
Edit: also, you may consider excluding the related file until a fix is deployed, please see here.
Hi, sorry for the delay. It wasn’t easy to extract a minimal piece of code that triggers this issue. I’m attaching a snippet below. The example isn’t very small, but whenever I tried removing any of the rows, the problem disappeared.
package fsstorage
import (
"github.com/gofiber/fiber/v2/log"
"os"
"path/filepath"
"strings"
)
func TempFile(dir, pattern string, perm os.FileMode) (f *os.File, err error) {
if dir == "" {
dir = os.TempDir()
}
var prefix, suffix string
if pos := strings.LastIndex(pattern, "*"); pos != -1 {
prefix, suffix = pattern[:pos], pattern[pos+1:]
}
name := filepath.Join(dir, prefix+suffix)
log.Info(name)
return
}
Hello @adam-sowinski_lyvecl,
Thank you for taking the time to provide this helpful reproducer. We understand that it wasn’t easy to provide, as it required a lot of trial and error.
In the meantime, we also worked on the issue and found a solution. We released it internally and tested it on your reproducer; it’s working well and doesn’t produce an error.
We are in the final stages of releasing it on Sonarqube Cloud, so you should expect this issue to be resolved in the next few days.
Thank you again for your time and we apologize for any inconvenience this may have caused.
Best,
Rudy
Good to hear that, thanks!
Do I need to change anything, or will it start working automatically after your release?
Nothing is expected from your side, it should indeed start working automatically once it’s released.