Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8728

Verifier.addDefaultParameters erases metadata if run more than once

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.15, 2.5.1
    • 2.5.2
    • None
    • None

    Description

      When processing sources with closure with parameter defaults, Verifier is wiping out the node metadata that contains the initial value expression.  At the end of addDefaultParameters(DefaultArgsAction action, MethodNode method), there is a for loop:

              for (Parameter parameter : parameters) {
                  // GRECLIPSE add
                  if (!parameter.hasInitialExpression()) continue;
                  // GRECLIPSE end
                  // remove default expression and store it as node metadata
                  parameter.putNodeMetaData(Verifier.INITIAL_EXPRESSION, parameter.getInitialExpression());
                  parameter.setInitialExpression(null);
              }
      

      This loop currently moves the initial expression to node metadata. However, when this method runs a second time, it takes null from getInitialExpression and puts that as the new metadata value, even if the node already has been processed.

      Adding a check hasInitialExpression solves this issue, making addDefaultParameters idempotent. This also prevent adding the metadata value in the first place for a parameter that never had a default value expression.

      Attachments

        Activity

          People

            paulk Paul King
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: