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

    Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.6, 3.0.0-beta-1
    • Component/s: Compiler
    • Labels:
      None
    • Environment:
      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

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

              Dates

              • Created:
                Updated:
                Resolved: