JFXtras / jfxtras

A supporting library for JavaFX, containing helper classes, extended layouts, controls and other interesting widgets.
http://jfxtras.org
Other
599 stars 123 forks source link

Calendar Picker: CalendarPickerControlSkin#toggle occasionally falls into an infinite loop #92

Closed bendardenne closed 6 years ago

bendardenne commented 6 years ago

Hi,

I have a calendar picker set up with mode=RANGE.

I have noticed that sometimes, selecting a range with the shift key held down will cause an infinite loop.

After some debugging, I noticed something weird: in CalendarPickerControlSkin#toggle, the following loop:

while (lWalker.equals(lTarget) == false)
{

// ...
    lWalker.add(Calendar.DATE, lDirection);
}

never exits. If I evaluate lWalker and lTarget at the iteration where they should be equal, I get that lTarget = 2018-03-01T20:48:47Z lWalker = 2018-03-01T20:48:47.780Z

It seems that calendarForToggleButton sometimes produces dates with non-zero milliseconds which causes the bug. Not sure why.

bendardenne commented 6 years ago

I can consistently reproduce this in the current development version, when selecting Jan 1, holding shift and then selecting Feb 28. For some reason not all range selections trigger the issue.

bendardenne commented 6 years ago

Changing CalendarPicker#constructDisplayedCalendar to :

private void constructDisplayedCalendar()
    {
        // init here, so deriveDisplayedCalendar in the skin will modify it accordingly
        Calendar calendar = Calendar.getInstance(getLocale());
        calendar.set(Calendar.MILLISECOND, 0);  
        setDisplayedCalendar( calendar );
    }

Seems to prevent the problem. Not entirely sure why it does not consistently happen for every date range though.

tbee commented 6 years ago

Thanks for reporting and examining! I'll take a look ASAP.

tbee commented 6 years ago

Created a test and fixed it. Thank you.