A stack overflow error occurred while analyzing file

Hi,

we are getting this error while analyzing java code with sonar scanner, i tried by disabling all rules but still facing same issue.

Could any one help help me to fix this and thanks for your help in advance.

ERROR: A stack overflow error occurred while analyzing file: 'src/main/java/com/sr/osfi/dao/HccDashboardRepositoryImpl.java'
java.lang.StackOverflowError: null
	at org.sonar.java.model.JParser.firstTokenIn(JParser.java:440)
	at org.sonar.java.model.JParser.convertSimpleName(JParser.java:1240)
	at org.sonar.java.model.JParser.createExpression(JParser.java:1759)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:1768)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.convertArguments(JParser.java:1057)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2062)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.createExpression(JParser.java:2074)
	at org.sonar.java.model.JParser.convertExpression(JParser.java:1748)
	at org.sonar.java.model.JParser.convertStatement(JParser.java:1332)
	at org.sonar.java.model.JParser.addStatementToList(JParser.java:1313)
	at org.sonar.java.model.JParser.convertBlock(JParser.java:1272)
	at org.sonar.java.model.JParser.processBodyDeclaration(JParser.java:996)
	at org.sonar.java.model.JParser.convertTypeDeclaration(JParser.java:738)
	at org.sonar.java.model.JParser.processBodyDeclaration(JParser.java:914)
	at org.sonar.java.model.JParser.convertCompilationUnit(JParser.java:564)
	at org.sonar.java.model.JParser.parse(JParser.java:312)
	at org.sonar.java.model.JParser.parse(JParser.java:249)
	at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:93)
	at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:65)
	at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:111)
	at org.sonar.java.JavaSquid.scan(JavaSquid.java:105)
	at org.sonar.plugins.java.JavaSquidSensor.execute(JavaSquidSensor.java:88)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy213.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
	at com.optum.edith.service.SonarService.scanProject(SonarService.java:72)
	at com.optum.edith.service.AnalysisService.cloneAndScanRepo(AnalysisService.java:142)
	at com.optum.edith.controller.ScanController.clone(ScanController.java:64)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:747)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1594)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)

2020-06-16 08:26:30.044 ERROR 1 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause

java.lang.StackOverflowError: null
	at org.sonar.java.model.JParser.firstTokenIn(JParser.java:440) ~[na:na]

Hi,

Could you provide your version of SonarQube, and a reproducer file?

 
Thx,
Ann

Hi @srujanch, @ganncamp,

We encountered the same error. Maybe I can provide some additional data points from our own experience:

  • SonarQube version: 8.4.2
  • SonarJava version: 6.5.1

I noticed this started happening when we enabled the java:S5790 rule to align our quality profile with the default profile. But note that I’m not confident it’s only this particular rule - just the first one that started causing the issue.
In our case, the affected file was a huge generated unit test file (6k LoC, most of it in a static {} block). I did some basic binary search by removing parts of the file to see if a particular block causes the error, but it looks like it’s the sheer size of the file.

We excluded that file from the analysis since it doesn’t make sense to analyze a generated file, so it’s not really a critical problem for us.

Hey @srujanch, @sandro-h,

It is likely that our parser is not able to create the AST, due to the amount of LOC in some generated statements. Can you try to increase the stack size allowed by your analysis?

It fixed similar issues in the past.

Cheers,
Michael