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

Groovy Map created via Map#withDefault does not insert unknown keys

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • groovy-plugin
    • None
    • Jenkins 2.414.1, Java 11, Groovy 2.4.21

      According to the documentation, a Groovy map created using Map#withDefault should add unknown keys referenced via Map#get or Map#[] to the map itself. When executing the below code snippet as a Jenkins pipeline, unknown keys will not be added to the map.

      def map = [:].withDefault { [] }
      map.get('A') << '1'
      map['B'] << '1'
      
      println map.toString() // prints [:], expected [A:[1], B:[1]]
      println map.keySet().toString() // prints [], expected [A, B]
      

      Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.

          [JENKINS-72453] Groovy Map created via Map#withDefault does not insert unknown keys

          Maurice created issue -
          Maurice made changes -
          Description Original: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], the Groovy Map#withDefault method should add unknown keys to the map. When executing the below code snippet as a Jenkins a pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
          New: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], a Groovy map created using Groovy Map#withDefault method should add unknown keys referenced via Map#get or #[] to the map itself. When executing the below code snippet as a Jenkins a pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
          Maurice made changes -
          Summary Original: Groovy Map#withDefault does not insert unknown keys New: Groovy Map created via Map#withDefault does not insert unknown keys
          Maurice made changes -
          Description Original: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], a Groovy map created using Groovy Map#withDefault method should add unknown keys referenced via Map#get or #[] to the map itself. When executing the below code snippet as a Jenkins a pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
          New: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], a Groovy map created using Groovy Map#withDefault should add unknown keys referenced via Map#get or #[] to the map itself. When executing the below code snippet as a Jenkins a pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
          Maurice made changes -
          Description Original: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], a Groovy map created using Groovy Map#withDefault should add unknown keys referenced via Map#get or #[] to the map itself. When executing the below code snippet as a Jenkins a pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
          New: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], a Groovy map created using Groovy Map#withDefault should add unknown keys referenced via Map#get or Map#[] to the map itself. When executing the below code snippet as a Jenkins a pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
          Maurice made changes -
          Description Original: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], a Groovy map created using Groovy Map#withDefault should add unknown keys referenced via Map#get or Map#[] to the map itself. When executing the below code snippet as a Jenkins a pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
          New: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], a Groovy map created using Map#withDefault should add unknown keys referenced via Map#get or Map#[] to the map itself. When executing the below code snippet as a Jenkins a pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
          Maurice made changes -
          Description Original: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], a Groovy map created using Map#withDefault should add unknown keys referenced via Map#get or Map#[] to the map itself. When executing the below code snippet as a Jenkins a pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.
          New: [According to the documentation|http://docs.groovy-lang.org/2.4.21/html/groovy-jdk/java/util/Map.html#withDefault(groovy.lang.Closure)], a Groovy map created using Map#withDefault should add unknown keys referenced via Map#get or Map#[] to the map itself. When executing the below code snippet as a Jenkins pipeline, unknown keys will not be added to the map.

          {code:java}
          def map = [:].withDefault { [] }
          map.get('A') << '1'
          map['B'] << '1'

          println map.toString() // prints [:], expected [A:[1], B:[1]]
          println map.keySet().toString() // prints [], expected [A, B]
          {code}

          Running the same snippet in a regular Groovy interpreter or the Jenkins script console will result in the expected output.

            vjuranek vjuranek
            ailuridae Maurice
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: