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

Throwing NPE when I use ternary operator with something special

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 3.0.3
    • 4.0.0-alpha-1, 3.0.4
    • parser
    • None
    • Win10/MacOS
      Zulu OpenJDK 11

    Description

      Hi,  I got NPE instead of empty string when I wrote the following snippet:

       

      static String a() {
       null
      }
      
      static String b() {
       ''
      }
      
      def x = a() ? [b(), a()].join(',') : b() // NPE
      //def x = a() ? [b(), a()] : b() // OK
      //def x = a() ? ([b(), a()]).join(',') : b() // OK
      
      x == ''
      

       

      Attachments

        Activity

          People

            daniel_sun Daniel Sun
            digitarts Huabin Zhang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: