Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-4683 static import collection task
  3. GROOVY-2773

Strange behaviour when passing chained methods (methodA().methodB().etc()) as parameters

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 2.5.6, 3.0.0-beta-1
    • Compiler
    • None
    • Ubuntu Gutsy Gibbon

    Description

      import org.joda.time.DateTime
      import static org.joda.time.DateTimeZone
      
      class EWUtils {
            static DateTime nowUTC() {
                    return new DateTime(UTC)
            }
      }
      
      //Inside a test case
      import static EWUtils.nowUTC
      ...
      DateTime baseDate = nowUTC()
      println "${baseDate.minusWeeks(1)} ${baseDate.minusWeeks(1).millis}"
      println "${nowUTC().minusWeeks(1)} ${nowUTC().minusWeeks(1).millis}"
      
      // The output
      2008-04-16T18:40:09.698Z 1208371209698
      2008-04-16T18:40:09.709Z 1208976009709
      

      The second println statement demonstrates the bug. The epoch time is approximately equal to the current time instead of being a week old as in the first example.
      The bug only manifests when nowUTC() belongs to another class - if I move it into the same class as the test it's OK

      Attachments

        1. groovybug.tar.gz
          165 kB
          Stephen Cresswell

        Activity

          People

            daniel_sun Daniel Sun
            cressie176 Stephen Cresswell
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: