OpenBankProject/OBP-API

Dont use Simple

Opened this issue · 0 comments

There are some SimpleDateFormat object used in concurrency environment. take the follow code as example. it should no be used in concurrency environment, especially in Utils object.

package code.api.util
import ...
object APIUtil extends MdcLoggable {

  val DateWithDay = "yyyy-MM-dd"
  val DateWithDay2 = "yyyyMMdd"
  val DateWithDay3 = "dd/MM/yyyy"
  val DateWithMinutes = "yyyy-MM-dd'T'HH:mm'Z'"
  val DateWithSeconds = "yyyy-MM-dd'T'HH:mm:ss'Z'"
  val DateWithMs = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
  val DateWithMsRollback = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
  
  val DateWithDayFormat = new SimpleDateFormat(DateWithDay)
  val DateWithSecondsFormat = new SimpleDateFormat(DateWithSeconds)
  val DateWithMsFormat = new SimpleDateFormat(DateWithMs)
  val DateWithMsRollbackFormat = new SimpleDateFormat(DateWithMsRollback)
...

The reason is just in the java documentation:
Shuang-screen 2019-04-24 pm10 01 36

So please find all SimpleDateFormat those not be this usage: created in method body, and not escape from method body.