Wrong behavior of LocalDateTimeStringConverter

Nir Lisker nlisker at gmail.com
Tue Jan 26 18:56:01 UTC 2021


I was looking at LocalDateTimeStringConverter and I think that there is a
possibility for wrong behavior.
The class uses an internal LdtConverter helper class that instantiates all
its fields, but they are not final. In its toString method, the chronology
field is reassigned if the formatting fails on that specific value. Then,
if another value is passed in, the new chronology field value is used,
which could give different results from having it been passed in first. In
addition, the default formatter and parser are built using the chronology
which was used at the time of their creation, and can become
inconsistent if the chronology changes later.

I think that this class should be immutable, with all null checks being
done on instantiation and assigning defaults based on that. I propose to
change this behavior as part of a refactoring effort I'm making in the
converters package.

Note that this internal class is used by LocalDate and LocalTime converters
as well.

- Nir

More information about the openjfx-dev mailing list