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

Ternary operator in a property assignment

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.18
    • Fix Version/s: None
    • Labels:
      None

      Description

      Why ternary operator in properties works incorrectly with strings?

      class Parent {
          def String name = (name == null || name == 'somebadname') ? 'default' : name
      }
      
      a = new Parent()
      println("name is: ${a.name}")
      
      b = new Parent(name: 'somebadname')
      println("name is: ${b.name}")
      
      c = new Parent(name: 'other')
      println("name is: ${c.name}")
      
      

      output:

      name is: default
      name is: somebadname
      name is: other
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              gekm gekm
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: