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

Property of object, which extends Map, couldn't be accessed

    Details

    • Similar Issues:

      Description

      Code (also used within library):

      class MyMap extends java.util.LinkedHashMap {
          public final String foobar
      
          MyMap(Map map) {
              super(map)
              this.foobar = 'foobar'
          }
      
          def myFooBar() {
              return this.foobar
          }
      }
      
      node {
          def m = new MyMap([foo: 'bar', bar: 'foo'])
          print "bar=${m.bar}"
          print "foo=${m.foo}"
          print "foobar=${m.foobar}"
          print "foobar=${m.myFooBar()}"
      } 

      Result:

      [Pipeline] node
      Running on Jenkins in /build/workspace
      [Pipeline] {
      [Pipeline] echo
      bar=foo
      [Pipeline] echo
      foo=bar
      [Pipeline] echo
      foobar=null
      [Pipeline] echo
      foobar=null
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      Finished: SUCCESS 

       

      Expected: 'foobar' value printed

      Conceptually and most likely overloaded getProperty(name) method has a bug...

        Attachments

          Activity

          Hide
          jglick Jesse Glick added a comment -

          As a workaround, check if @ notation (explicit field access) helps.

          Show
          jglick Jesse Glick added a comment - As a workaround, check if @ notation (explicit field access) helps.
          Hide
          dicomj23 Dicom J added a comment - - edited

          Jesse Glick, thanks, will try

          Show
          dicomj23 Dicom J added a comment - - edited Jesse Glick , thanks, will try
          Hide
          dicomj23 Dicom J added a comment - - edited

          Jesse Glick, @ notation works, both internally as `def myFooBar() { this.@foobar }` and externally as `m.@foobar`.
          Again, thanks a lot!!!

          Show
          dicomj23 Dicom J added a comment - - edited Jesse Glick , @ notation works, both internally as `def myFooBar() { this.@foobar }` and externally as `m.@foobar`. Again, thanks a lot!!!

            People

            • Assignee:
              Unassigned
              Reporter:
              dicomj23 Dicom J
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: