[错误] TimeUtils 中的 ThreadLocal 缓存导致 Locale/TimeZone 状态永久保持

作者: QiuYucheng2003创建于 2026年2月22日更新于 2026年2月22日
标签bug

Description of the bug In TimeUtils.java, ThreadLocal<Map<String, SimpleDateFormat>> is used to cache time formatters for performance optimization. However, when new SimpleDateFormat(pattern) is executed, the instance implicitly depends on and binds the system-wide Locale and TimeZone created at the time of the current thread's creation. In a multi-threaded environment on Android, background worker threads (such as thread pools) are long-lived and highly reusable. If the user switches the system language or crosses physical time zones during application execution, the reused old thread that the system assigns will blindly use the old formatters left in the ThreadLocal for rendering, resulting in "presentation layer fragmentation" on the same application interface (such as some output in French and some in English), severely compromising data consistency and user experience, and making it difficult to detect with conventional code review. - AndroidUtilCode version: - Device model where the bug occurred: - Android version of the device: ## Related code Problem code location (TimeUtils.java):

内容来源: Blankj/AndroidUtilCode