|
|
|
Sorry it's taken so long. Have finally found time to reproduce in isolation (and with a proper test case this time).
We're using grails 1.0.2 which ships with groovy 1.5.4 Also fails on OSX 10.x see /test/unit/example/UtilsTest in the (soon to be) attached but if it is a problem that happens only within Grails, wouldn't it be then a Grails bug?
I only said I'm using grails and therefore the version of groovy is 1.5.4. I never said the problem only occurs with grails. In fact if you look at the attached source there's nothing remotely grails dependent in the example. It's just two groovy classes and a test case that extends GroovyTestCase.
This script (reworking of attached) reproduces the problem:
class DateTime {
long millis
DateTime() { millis = new Date().getTime() }
DateTime(long millis) { this.millis = millis }
DateTime minusWeeks(Integer numWeeks) {
return new DateTime(millis - (1000 * 60 * 60 * 24 * 7 * numWeeks))
}
}
class Utils {
static nowUTC() { return new DateTime() }
}
import static Utils.nowUTC
DateTime baseDate = Utils.nowUTC()
Long now = new Date().getTime()
Long lastWeekFromBaseDate = baseDate.minusWeeks(1).millis
Long lastWeekInline = Utils.nowUTC().minusWeeks(1).millis
assert now > lastWeekFromBaseDate, "Should have passed"
assert now > lastWeekInline, "Here's the bug"
Commenting out the import static line and the code works fine. The code isn't using the static import so that both variations should work with just the one line change but the behavior is the same in both cases. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Only... I have problems reproducing this issue. Which version of Groovy did you use? Can you give an example that uses no external lib?