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

Throwing NPE when I use ternary operator with something special

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 3.0.3
    • Fix Version/s: 4.0.0-alpha-1, 3.0.4
    • Component/s: parser
    • Labels:
      None
    • Environment:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: