rcongiu / Hive-JSON-Serde

Read - Write JSON SerDe for Apache Hive.
Other
733 stars 391 forks source link

Use of SimpleDateFormat is not Threadsafe #227

Open pettyjamesm opened 4 years ago

pettyjamesm commented 4 years ago

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: