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

Groovy 3.0.5: Closure delegate is not working properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.2, 3.0.3, 3.0.4, 3.0.5, 2.5.14
    • 2.5.15, 3.0.8, 4.0.0-alpha-3
    • None
    • None

    Description

      In Grails Views, we are using closures to generate JSON using StreamingJsonBuilder. The HAL implementation for an entity now generates an incorrect JSON after updating to Groovy 3.

      Here is the problem code snipped from grails.plugin.json.view.api.internal.DefaultHalViewHelper#links

      jsonDelegate.call(LINKS_ATTRIBUTE) {
          call(SELF_ATTRIBUTE) {
              call HREF_ATTRIBUTE, viewHelper.link(resource: object, method: HttpMethod.GET, absolute: true)
              call HREFLANG_ATTRIBUTE, locale.toString()
      
              call TYPE_ATTRIBUTE, contentType
          }
      
          Set<Link> links = getLinks(object)
          for (link in links) {
              call(link.rel) {
                  call HREF_ATTRIBUTE, link.href
                  call HREFLANG_ATTRIBUTE, link.hreflang?.toString() ?: locale.toString()
                  def linkType = link.contentType
                  if (linkType) {
                      call TYPE_ATTRIBUTE, linkType
                  }
              }
          }
      }
      

       
      Although the `resolveStatergy` for the closures is `DELEGATE_FIRST` but I believe that is not working correctly because it works if I change the above to:

      delegate.call (...
      

       

      To reproduce the issue please checkout https://github.com/grails/grails-views/commits/bugs/groovy-9962

       

      Attachments

        1. JsonViewWritableScript.groovy
          6 kB
          Eric Milles
        2. StreamingJsonBuilder.java
          30 kB
          Eric Milles

        Activity

          People

            emilles Eric Milles
            behlp Puneet Behl
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h