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

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

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.5.6
    • Fix Version/s: None
    • Component/s: Static Type Checker
    • Labels:
      None

      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

            • Assignee:
              Unassigned
              Reporter:
              drosenbauer Devin Rosenbauer
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: