PDA

View Full Version : [FIXED] [1.2.3] TimeField has infinite loop



epishkin
29 Mar 2009, 1:40 PM
gxt 1.2.3
JDK 1.6
IDEA 8.01
WindowsXP

I could reproduce the infinite loop in com.extjs.gxt.ui.client.widget.form.TimeField#initList() method yesterday. And can't reproduce it now. Do you have any idea what could be wrong? GXT doesn't like March 29? :D

Sample code that eats 100% of CPU:


import com.extjs.gxt.ui.client.widget.form.TimeField;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class TimeFieldSample implements EntryPoint {
public void onModuleLoad() {
RootPanel.get().add(new TimeField());
}
}
I was debugging com.extjs.gxt.ui.client.widget.form.TimeField#initList


@Override
protected void initList() {
initialized = true;
DateWrapper min = minValue != null ? new DateWrapper(minValue) : new DateWrapper();
if (minValue == null) {
min = min.clearTime();
}

DateWrapper max = maxValue != null ? new DateWrapper(maxValue) : new DateWrapper();
if (maxValue == null) {
max = max.clearTime().addMinutes((24 * 60) - 1);
}

List times = new ArrayList();
while (min.before(max)) {
Time r = new Time(min.asDate());
r.set("text", getFormat().format(min.asDate()));
times.add(r);
min = min.addMinutes(increment);
}

ListStore store = new ListStore();
store.add(times);

setStore(store);
setDisplayField("text");
super.initList();
}
and found that min = min.addMinutes(increment); was looping around 2AM: 2:00AM -> 2:15AM -> 2:30AM -> 2:45AM -> 2:00AM
So the code can't exit from the 'while' loop.

That bug broke our application on March 29'th so I was looking for any workaround. And the following code worked fine:


@Override
protected void initList() {
initialized = true;
DateWrapper min = minValue != null ? new DateWrapper(minValue) : new DateWrapper();
if (minValue == null) {
min = min.clearTime();
}

DateWrapper max = maxValue != null ? new DateWrapper(maxValue) : new DateWrapper();
if (maxValue == null) {
max = max.clearTime().addMinutes((24 * 60) - 1);
}

List times = new ArrayList();
int count = 0;
while (min.before(max)) {
Time r = new Time(min.asDate());
r.set("text", getFormat().format(min.asDate()));
times.add(r);
min = min.clearTime().addMinutes(count*increment);
count++;
}

ListStore store = new ListStore();
store.add(times);

setStore(store);
setDisplayField("text");
super.initList();
}
Any ideas?

I live in Ukraine. And yesterday we switched to the Summer time. Probably these 2 days when we switch to Summer/Winter time are not good days for GXT...

As I know we switch to Summer time at 2:00AM!

kht
30 Mar 2009, 1:42 AM
os: mac osx 10.5
gxt: 1.2.3
locale: de_AT

i had the same problem here in austria. maybe it really depends on the swiching to summer time. endless initialization... yesterday (sunday) whole evening.
this morning all started to work again without any problems.

regards, kht

sven
30 Mar 2009, 3:17 AM
Yes it depends on switching to summertime. I have a fix for this ready. So next time it should not happen again ;)

sven
1 Apr 2009, 4:28 AM
Fixed in SVN.