Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of SimpleDateFormat is not Threadsafe #227

Open
pettyjamesm opened this issue Aug 25, 2020 · 0 comments · May be fixed by #228
Open

Use of SimpleDateFormat is not Threadsafe #227

pettyjamesm opened this issue Aug 25, 2020 · 0 comments · May be fixed by #228

Comments

@pettyjamesm
Copy link

The javadoc for SimpleDateFormat will confirm: this class isn’t thread safe. Internally, it mutates several mutable fields in the process of parsing and formatting. Accessing instances of SimpleDateFormat from multiple threads concurrently (to perform either operation) can lead to either unexpected “impossible“ exceptions or silently corrupt results.

To fix this issue, the following usages (at least, I only looked through 1.3.8 not master to find these) need to be modified to either put the SimpleDateFormat inside of a ThreadLocal, create each SimpleDateFormat instance per usage, or use JDK 8’s DateTimeFormatter which is immutable and thread safe:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant