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

Safe navigation operator does not perform null-check for field access under CompileStatic

    XMLWordPrintableJSON

Details

    Description

      Given this file:

      SafeNavigation.groovy
      @groovy.transform.CompileStatic
      class SafeNavigation {
      
      	String name1
      	public String name2
      	
          public static void main(String[] args) {
              SafeNavigation test
              
              println test?.name1 // 'null'
              println test?.name2 // NullPointerException
      	}
      }
      

      an NPE will be thrown at the second line null safe navigation. Remove the @CompileStatic and the check works as expected.

      Or see attached test case.

      Attachments

        Activity

          People

            melix Cédric Champeau
            jespersm Jesper Steen Møller
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: