Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-72271

There is already a child [METHOD] ... with the name ... in [CLASS] ...

      I am facing issues trying to recordCoverage

      recordCoverage(tools: [[parser: 'COBERTURA', pattern: 'Coverage/Report/Cobertura.xml']])

      The report is generated by Unity.

      The problem just recently appeared after an update of Jenkins master from 2.414.1 to 2.414.3 and installing available plugin updates (doing this once a month).

      Plugin works for other pipelines, it only fails recording coverage for those using Unity.

      Output

      10:57:15  Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to <node>
      10:57:15  		at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784)
      10:57:15  		at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:356)
      10:57:15  		at hudson.remoting.Channel.call(Channel.java:1000)
      10:57:15  		at hudson.FilePath.act(FilePath.java:1192)
      10:57:15  		at hudson.FilePath.act(FilePath.java:1181)
      10:57:15  		at io.jenkins.plugins.coverage.metrics.steps.CoverageRecorder.recordCoverageResults(CoverageRecorder.java:477)
      10:57:15  		at io.jenkins.plugins.coverage.metrics.steps.CoverageRecorder.perform(CoverageRecorder.java:408)
      10:57:15  		at io.jenkins.plugins.coverage.metrics.steps.CoverageRecorder.perform(CoverageRecorder.java:397)
      10:57:15  		at io.jenkins.plugins.coverage.metrics.steps.CoverageStep$Execution.run(CoverageStep.java:364)
      10:57:15  		at io.jenkins.plugins.coverage.metrics.steps.CoverageStep$Execution.run(CoverageStep.java:332)
      10:57:15  		at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
      10:57:15  		at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      10:57:15  Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: ce62a997-1555-488e-9308-321114885098
      10:57:15  java.lang.IllegalArgumentException: There is already a child [METHOD] Transition() <0> with the name Transition() in [CLASS] Core.Handlers.MovementHandler <54, LINE: 33.27% (169/508)>
      10:57:15  	at edu.hm.hafner.coverage.Node.addChild(Node.java:165)
      10:57:15  	at edu.hm.hafner.coverage.parser.CoberturaParser.readClassOrMethod(CoberturaParser.java:189)
      10:57:15  	at edu.hm.hafner.coverage.parser.CoberturaParser.readPackage(CoberturaParser.java:130)
      10:57:15  	at edu.hm.hafner.coverage.parser.CoberturaParser.parseReport(CoberturaParser.java:101)
      10:57:15  	at edu.hm.hafner.coverage.CoverageParser.parse(CoverageParser.java:75)
      10:57:15  	at io.jenkins.plugins.coverage.metrics.steps.CoverageReportScanner.processFile(CoverageReportScanner.java:60)
      10:57:15  	at io.jenkins.plugins.util.AgentFileVisitor.scanFiles(AgentFileVisitor.java:114)
      10:57:15  	at io.jenkins.plugins.util.AgentFileVisitor.invoke(AgentFileVisitor.java:93)
      10:57:15  	at io.jenkins.plugins.util.AgentFileVisitor.invoke(AgentFileVisitor.java:39)
      10:57:15  	at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3578)
      10:57:15  	at hudson.remoting.UserRequest.perform(UserRequest.java:211)
      10:57:15  	at hudson.remoting.UserRequest.perform(UserRequest.java:54)
      10:57:15  	at hudson.remoting.Request$2.run(Request.java:377)
      10:57:15  	at hudson.remoting.InterceptingExecutorService.lambda$wrap$0(InterceptingExecutorService.java:78)
      10:57:15  	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      10:57:15  	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      10:57:15  	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      10:57:15  	at java.base/java.lang.Thread.run(Thread.java:829)
      

      Is there any chance you can help me resolving the issue? Maybe I can just reset some cache of the pipeline or delete existing coverage records of that pipeline?

      Best,

      Thomas

          [JENKINS-72271] There is already a child [METHOD] ... with the name ... in [CLASS] ...

          Ulli Hafner added a comment -

          Do you have the ignoreParsingErrors property enabled? See https://github.com/jenkinsci/code-coverage-api-plugin/pull/788

          Ulli Hafner added a comment - Do you have the ignoreParsingErrors property enabled? See https://github.com/jenkinsci/code-coverage-api-plugin/pull/788

          Thomas added a comment -

          drulli thank you very much for the exceptional fast response. I was not specifying it so far and just added the option, i.e. now using

           recordCoverage(ignoreParsingErrors: true, tools: [[parser: 'COBERTURA', pattern: 'Coverage/Report/Cobertura.xml']])
          

          and first tests indicate it works.

          Thomas added a comment - drulli thank you very much for the exceptional fast response. I was not specifying it so far and just added the option, i.e. now using recordCoverage(ignoreParsingErrors: true , tools: [[parser: 'COBERTURA' , pattern: 'Coverage/Report/Cobertura.xml' ]]) and first tests indicate it works.

          Ulli Hafner added a comment -

          I added this extra validation to detect broken XML files. Do you have an idea why there are two methods with the same name and signature in your report file? This indicates that something is broken during the report generation.

          Ulli Hafner added a comment - I added this extra validation to detect broken XML files. Do you have an idea why there are two methods with the same name and signature in your report file? This indicates that something is broken during the report generation.

          Thomas added a comment -

          I dont know why exactly Unity creates duplicates entries. I informed some other dev to check it.

          Thomas added a comment - I dont know why exactly Unity creates duplicates entries. I informed some other dev to check it.

          Christopher added a comment - - edited

          I can't speak for Unity, but I know where I work we've got some Javascript code that has a function defined in two places in one file (conditionally - one's a mock the other is the real one). That Javascript has code coverage run on it with istanbul, and the result is output in cobertura format so that the Jenkins coverage can parse it. Looking in the xml file, there are two different, legitimate, versions of the function in the file on different lines - but the parsing is only accounting for name and signature, so it errors out with this duplicate error.

          So, while maybe rare, there are actually things that can create duplicate methods in a cobertura report. I know nothing about Unity, so I can't say if something similar might be the issue - but it's not necessarily something broken during report generation.

          (the ignore errors setting does work around it - and fortunately I suspect one of those duplicates is never called in test, so it's not an immediate problem, but this ticket a parsing bug, not a generator bug)

          Christopher added a comment - - edited I can't speak for Unity, but I know where I work we've got some Javascript code that has a function defined in two places in one file (conditionally - one's a mock the other is the real one). That Javascript has code coverage run on it with istanbul, and the result is output in cobertura format so that the Jenkins coverage can parse it. Looking in the xml file, there are two different, legitimate, versions of the function in the file on different lines - but the parsing is only accounting for name and signature, so it errors out with this duplicate error. So, while maybe rare, there are actually things that can create duplicate methods in a cobertura report. I know nothing about Unity, so I can't say if something similar might be the issue - but it's not necessarily something broken during report generation. (the ignore errors setting does work around it - and fortunately I suspect one of those duplicates is never called in test, so it's not an immediate problem, but this ticket a parsing bug, not a generator bug)

          Ulli Hafner added a comment -
          That Javascript has code coverage run on it with istanbul, and the result is output in cobertura format so that the Jenkins coverage can parse it. Looking in the xml file, there are two different, legitimate, versions of the function in the file on different lines
          

          But these two methods must have a different parent, or am I missing something?

          Ulli Hafner added a comment - That Javascript has code coverage run on it with istanbul, and the result is output in cobertura format so that the Jenkins coverage can parse it. Looking in the xml file, there are two different, legitimate, versions of the function in the file on different lines But these two methods must have a different parent, or am I missing something?

          Christopher added a comment -

          I think you're missing something - but it's admittedly a weird corner case. I'm only passingly familiar with the part of our code that's resulting in this unusual coverage report myself, so I hope I've narrowed this down right. But basically we've got:

          class SomeClass {
            static aMethod() {
              if (oneCondition) {
                const firstObject = {
                  aFunction() {},
                  anotherFunction() {},
                }
              }
          
              if (anotherCondition) {
                const secondObject = {
                  aFunction() {}
                  anotherFunction() {},
                }
              }
            }
          }

          Both copies of aFunction and anotherFunction are recorded in the coverage report from istanbul. The XML file has a methods element that is effectively "flat", having one entry for each function in the file - whether those methods are members of the class or nested functions inside other functions. So the only distinction between the entries is the line number (the line numbers in the xml for those functions appear to be the line numbers where the containing object is defined.. I hope that made sense).

          So yeah, it's a bit weird, and we could probably write it differently. But it seems to be a valid case that produces a duplicate - unless there is actually something in this that should be able to distinguish the functions as different that the report is in fact missing, other than the line numbers. I can't think of what that might be, but I don't know the details of the cobertura format.

          Christopher added a comment - I think you're missing something - but it's admittedly a weird corner case. I'm only passingly familiar with the part of our code that's resulting in this unusual coverage report myself, so I hope I've narrowed this down right. But basically we've got: class SomeClass { static aMethod() { if (oneCondition) { const firstObject = { aFunction() {}, anotherFunction() {}, } } if (anotherCondition) { const secondObject = { aFunction() {} anotherFunction() {}, } } } } Both copies of aFunction and anotherFunction are recorded in the coverage report from istanbul. The XML file has a methods element that is effectively "flat", having one entry for each function in the file - whether those methods are members of the class or nested functions inside other functions. So the only distinction between the entries is the line number (the line numbers in the xml for those functions appear to be the line numbers where the containing object is defined.. I hope that made sense). So yeah, it's a bit weird, and we could probably write it differently. But it  seems to be a valid case that produces a duplicate - unless there is actually something in this that should be able to distinguish the functions as different that the report is in fact missing, other than the line numbers. I can't think of what that might be, but I don't know the details of the cobertura format.

          Manfred added a comment -

          Had the same issue, but don't know why because my typescript code has no duplicates. I searched in transpiled code but also didn't find any hints. We are using vitest with reporter v8. I think vitest has it's own transpilation...
          I found this duplicate in the coverage output:

           

          Anyway, for now this problem is fixed with the `ignoreParsingErrors` flag.
          Thanks for the great plugin.

          Manfred added a comment - Had the same issue, but don't know why because my typescript code has no duplicates. I searched in transpiled code but also didn't find any hints. We are using vitest with reporter v8. I think vitest has it's own transpilation... I found this duplicate in the coverage output:   Anyway, for now this problem is fixed with the `ignoreParsingErrors` flag. Thanks for the great plugin.

          Ulli Hafner added a comment -

          Are the lines 20 and 56 within the same method parseFilterString? Currently the parser assumes that the method contains all lines within one method block. Maybe it would help to notify the vitest team that the format somehow is broken.

          Ulli Hafner added a comment - Are the lines 20 and 56 within the same method parseFilterString? Currently the parser assumes that the method contains all lines within one method block. Maybe it would help to notify the vitest team that the format somehow is broken.

          Manfred added a comment -

          No, unfortunately not. Line 56 has nothing at all to do with the problematic function. The project is also organised in a monorepo, maybe that is a problem. 
          I also noticed that I have a lot of such duplicates in the xml. The example was just the first one that ran into errors. 
          It may also be due to how I bind an anonymous function to a property in an object. Many of the problematic funtions lokk like this.

          I will investigate this further and maybe inform the vitest team.
          Thx again

          Manfred added a comment - No, unfortunately not. Line 56 has nothing at all to do with the problematic function. The project is also organised in a monorepo, maybe that is a problem.  I also noticed that I have a lot of such duplicates in the xml. The example was just the first one that ran into errors.  It may also be due to how I bind an anonymous function to a property in an object. Many of the problematic funtions lokk like this. I will investigate this further and maybe inform the vitest team. Thx again

            drulli Ulli Hafner
            thomashp Thomas
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: