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

Diamond Operator for own class causes NullPointerException if Static Compilation is enabled

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.3, 2.4.7
    • Fix Version/s: 2.4.8
    • Labels:
      None
    • Environment:

      Description

      When the diamond operator is used to instantiate a generic and the generic is specialized on the class the method is in, static compilation fails with a Nullpointer Exception. Dynamic compilation works, also replacing the diamond operator with the exact type or using "raw" typing.

      The following code reproduces the bug on both machines(listed in Environment):

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class BugTest {
          private class CompilerKiller<T> {
              private T t
              public CompilerKiller(T t){
                  this.t = t
              }
          }
      
          public void "This causes a NPE"(){
              CompilerKiller<BugTest> sample = new CompilerKiller<>(this)
          }
      
          public void "This causes a NPE as well"(){
              CompilerKiller<BugTest> sample = new CompilerKiller<>(new BugTest())
          }
      
          public void "This does work"(){
              CompilerKiller<BugTest> sample = new CompilerKiller<BugTest>(this)
          }
      
          public void "This works as well"(){
              CompilerKiller<BugTest> sample = new CompilerKiller(this)
          }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                paulk Paul King
                Reporter:
                leuprechtroman Roman Leuprecht
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: