Title: [Bug] Memory Leak (Unmanaged ThreadLocal) in SpotifyApi via SIMPLE_DATE_FORMAT · Issue #450 · spotify-web-api-java/spotify-web-api-java · GitHub
Open Graph Title: [Bug] Memory Leak (Unmanaged ThreadLocal) in SpotifyApi via SIMPLE_DATE_FORMAT · Issue #450 · spotify-web-api-java/spotify-web-api-java
X Title: [Bug] Memory Leak (Unmanaged ThreadLocal) in SpotifyApi via SIMPLE_DATE_FORMAT · Issue #450 · spotify-web-api-java/spotify-web-api-java
Description: Bug Description In se.michaelthelin.spotify.SpotifyApi, the static field SIMPLE_DATE_FORMAT utilizes a ThreadLocal
Open Graph Description: Bug Description In se.michaelthelin.spotify.SpotifyApi, the static field SIMPLE_DATE_FORMAT utilizes a ThreadLocal
X Description: Bug Description In se.michaelthelin.spotify.SpotifyApi, the static field SIMPLE_DATE_FORMAT utilizes a ThreadLocal<SimpleDateFormat> to handle date parsing and formatting. However, there is n...
Opengraph URL: https://github.com/spotify-web-api-java/spotify-web-api-java/issues/450
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug] Memory Leak (Unmanaged ThreadLocal) in SpotifyApi via SIMPLE_DATE_FORMAT","articleBody":"**Bug Description**\nIn `se.michaelthelin.spotify.SpotifyApi`, the static field `SIMPLE_DATE_FORMAT` utilizes a `ThreadLocal\u003cSimpleDateFormat\u003e` to handle date parsing and formatting. However, there is no mechanism to call `ThreadLocal.remove()` to clean up the resource. \n\n**Reproduction Steps**\nThis issue triggers when the SDK is integrated into server-side gateway applications or any environment utilizing long-lived thread pools (e.g., Spring Boot default executors, Tomcat). \n\nMinimal reproduction concept:\n```java\nExecutorService pool = Executors.newFixedThreadPool(200);\nfor (int i = 0; i \u003c 10000; i++) {\n pool.submit(() -\u003e {\n try {\n // Each thread in the pool initializes its own SimpleDateFormat\n SpotifyApi.parseDefaultDate(\"2023-01-01T12:00:00\");\n } catch (Exception e) {\n e.printStackTrace();\n }\n });\n}\n// The ThreadLocalMap of all 200 core threads will permanently hold a SimpleDateFormat instance, as .remove() is never invoked.\n\n\n\nImpact\nThis Unmanaged ThreadLocal (UTL) usage leads to memory leaks. In high-concurrency environments with large thread pools, the uncollected SimpleDateFormat instances will gradually inflate the heap memory, potentially leading to performance degradation or OutOfMemoryError over time.\n\nSuggested Fix\nSince the project likely uses Java 8+, the most robust solution is to replace ThreadLocal\u003cSimpleDateFormat\u003e with java.time.format.DateTimeFormatter. DateTimeFormatter is immutable and inherently thread-safe, eliminating the need for ThreadLocal entirely.","author":{"url":"https://github.com/QiuYucheng2003","@type":"Person","name":"QiuYucheng2003"},"datePublished":"2026-02-20T03:04:41.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/450/spotify-web-api-java/issues/450"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2f054e77-e2fe-59b5-98bd-e31fcb19744a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CB82:1922CE:41BF91:597089:6A626DCB |
| html-safe-nonce | b8fe867c77b4871f46851c3105975a50e832650144a00be973410c620a75e461 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQjgyOjE5MjJDRTo0MUJGOTE6NTk3MDg5OjZBNjI2RENCIiwidmlzaXRvcl9pZCI6IjMyNzI0MjA5NDI3ODcyNzYyMzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e21fda04bfa4198ede723e6321ec99cdc235b336ec43cba1b9133b092ee23a33 |
| hovercard-subject-tag | issue:3966298479 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/spotify-web-api-java/spotify-web-api-java/450/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2ec294f733ddb89b31457948c30322654e707700be1cd42a295a92878dc0512a/spotify-web-api-java/spotify-web-api-java/issues/450 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2ec294f733ddb89b31457948c30322654e707700be1cd42a295a92878dc0512a/spotify-web-api-java/spotify-web-api-java/issues/450 |
| og:image:alt | Bug Description In se.michaelthelin.spotify.SpotifyApi, the static field SIMPLE_DATE_FORMAT utilizes a ThreadLocal |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | QiuYucheng2003 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 19769ef9d383a84eeab48bb9b309078c20f4532b73eae2f9713b18406513e0ad |
| turbo-cache-control | no-preview |
| go-import | github.com/spotify-web-api-java/spotify-web-api-java git https://github.com/spotify-web-api-java/spotify-web-api-java.git |
| octolytics-dimension-user_id | 90800172 |
| octolytics-dimension-user_login | spotify-web-api-java |
| octolytics-dimension-repository_id | 18928344 |
| octolytics-dimension-repository_nwo | spotify-web-api-java/spotify-web-api-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 18928344 |
| octolytics-dimension-repository_network_root_nwo | spotify-web-api-java/spotify-web-api-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 76dc6b11f13eaeec1329217c9f16c262ade27a1e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width