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

Static type checking fails on java.sql.Timestamp when compared to null

    XMLWordPrintableJSON

Details

    Description

      The following class fails when compiled by Groovy 2.5.6 (via Gradle). The error is:

      src/main/groovy/Bug.groovy: 11: [Static type checking] - Reference to method is ambiguous. Cannot choose between [boolean java.sql.Timestamp#equals(java.sql.Timestamp), boolean java.sql.Timestamp#equals(java.lang.Object)]
       @ line 11, column 13.
                 if (timestamp != null) {
                     ^
      

      Class code for Bug.groovy -

      import groovy.transform.TypeChecked
      
      import java.sql.Timestamp
      
      @TypeChecked
      class Bug {
      
          public void bug() {
              java.sql.Timestamp timestamp = new Timestamp(new Date().getTime());
      
              if (timestamp != null) {
      
              }
          }
      
      }
      

      Expected behavior: Groovy compiles "x != null" without reference to Java's equals.

      Attachments

        Activity

          People

            emilles Eric Milles
            drosenbauer Devin Rosenbauer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m