Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-11502

TooManyResultsException in api/components/show on PR which name is equal to the main branch name

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 7.4
    • Fix Version/s: 7.5
    • Component/s: Web API
    • Labels:
    • Edition:
      Developer
    • Production Notes:
      None

      Description

      Call to the WS api/components/show can fail with TooManyResultException when a user created a Pull request which key is the same as a long living branch name.

      Sample stacktrace (from SonarCloud):

      Fail to process request http://sonarcloud.io/api/navigation/component?componentKey=GenesisBarcodeParser&pullRequest=master
      org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned by selectOne(), but found: 2
      	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:81)
      	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:83)
      	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
      	at com.sun.proxy.$Proxy79.selectByKeyAndBranchKey(Unknown Source)
      	at org.sonar.db.component.ComponentDao.selectByKeyAndPullRequest(ComponentDao.java:280)
      	at org.sonar.server.component.ComponentFinder.getByKeyAndPullRequest(ComponentFinder.java:148)
      	at org.sonar.server.component.ComponentFinder.getByKeyAndOptionalBranchOrPullRequest(ComponentFinder.java:161)
      	at org.sonar.server.ui.ws.ComponentAction.handle(ComponentAction.java:152)
      	at org.sonar.server.ws.WebServiceEngine.execute(WebServiceEngine.java:110)
      	at org.sonar.server.ws.WebServiceFilter.doFilter(WebServiceFilter.java:88)
      	at org.sonar.server.platform.web.MasterServletFilter$GodFilterChain.doFilter(MasterServletFilter.java:126)
      	at org.sonar.server.platform.web.MasterServletFilter.doFilter(MasterServletFilter.java:95)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      	at org.sonar.server.user.UserSessionFilter.doFilter(UserSessionFilter.java:87)
      	at org.sonar.server.user.UserSessionFilter.doFilter(UserSessionFilter.java:71)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      	at org.sonar.server.platform.web.CacheControlFilter.doFilter(CacheControlFilter.java:76)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      	at org.sonar.server.platform.web.SecurityServletFilter.doHttpFilter(SecurityServletFilter.java:76)
      	at org.sonar.server.platform.web.SecurityServletFilter.doFilter(SecurityServletFilter.java:48)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      	at org.sonar.server.platform.web.RedirectFilter.doFilter(RedirectFilter.java:61)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      	at org.sonar.server.platform.web.requestid.RequestIdFilter.doFilter(RequestIdFilter.java:63)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      	at org.sonar.server.platform.web.RootFilter.doFilter(RootFilter.java:62)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      	at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
      	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:199)
      	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
      	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
      	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
      	at ch.qos.logback.access.tomcat.LogbackValve.invoke(LogbackValve.java:256)
      	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
      	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
      	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
      	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
      	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
      	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)
      

      Reproducer:

      • analyse project to create main branch
        sonar-scanner
        
      • analyse project as if a pull request named {master}

        (default name of the main branch)

        sonar-scanner -Dsonar.pullrequest.branch=master -Dsonar.pullrequest.key=master -Dsonar.pullrequest.base=master
        

      Fix:

      SQL method selectByKeyAndBranchKey must be updated to filter on PROJECT_BRANCHES.BRANCH_TYPE column:

        Attachments

          Activity

            People

            Assignee:
            sebastien.lesaint Sebastien Lesaint
            Reporter:
            sebastien.lesaint Sebastien Lesaint
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Due:
              Created:
              Updated:
              Resolved: