Title: feat: implement size-limited LRU cache for JSON Schema validation by joaquinescalante23 · Pull Request #845 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: feat: implement size-limited LRU cache for JSON Schema validation by joaquinescalante23 · Pull Request #845 · modelcontextprotocol/java-sdk
X Title: feat: implement size-limited LRU cache for JSON Schema validation by joaquinescalante23 · Pull Request #845 · modelcontextprotocol/java-sdk
Description: I noticed that the current DefaultJsonSchemaValidator implementations (Jackson 2 and 3) were using an unbounded ConcurrentHashMap for schema caching, which could lead to memory leaks in long-running processes if exposed to a large number of dynamic schemas. This PR addresses the TODO in both modules by: Replacing the unbounded map with a thread-safe LRU Cache (defaulting to 1024 entries) using LinkedHashMap. Making the cache size configurable via constructors for greater flexibility. Improving the generateCacheKey logic to use a stable JSON representation of the schema instead of the default hashCode(), preventing potential collisions and ensuring cache hits are reliable regardless of map order. These changes significantly improve the resilience and resource management of the SDK when validating complex MCP tool outputs.
Open Graph Description: I noticed that the current DefaultJsonSchemaValidator implementations (Jackson 2 and 3) were using an unbounded ConcurrentHashMap for schema caching, which could lead to memory leaks in long-runnin...
X Description: I noticed that the current DefaultJsonSchemaValidator implementations (Jackson 2 and 3) were using an unbounded ConcurrentHashMap for schema caching, which could lead to memory leaks in long-runnin...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/pull/845
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:82fbe099-a672-1739-6ac1-94ee3239988b |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DE34:161EE9:BE65AD:104687A:6A619A24 |
| html-safe-nonce | 9fd5ad5369f72deb4aba343ec4b48d12dd836d7ba358d6030fc266f07e70a469 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTM0OjE2MUVFOTpCRTY1QUQ6MTA0Njg3QTo2QTYxOUEyNCIsInZpc2l0b3JfaWQiOiI1NzAxNzg2NzAwMzMyNzY3NzgwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0f029f48ecba4994b55b7ee2e43cea31d54c72898db9e13ba297d857a0e28a4e |
| hovercard-subject-tag | pull_request:3353531317 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/modelcontextprotocol/java-sdk/pull/845/files |
| twitter:image | https://avatars.githubusercontent.com/u/111885524?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/111885524?s=400&v=4 |
| og:image:alt | I noticed that the current DefaultJsonSchemaValidator implementations (Jackson 2 and 3) were using an unbounded ConcurrentHashMap for schema caching, which could lead to memory leaks in long-runnin... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | c28c2f6607f2aacbd934868d997038895c9780d08babfe918550d73773326f4c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/java-sdk git https://github.com/modelcontextprotocol/java-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 919609219 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/java-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 919609219 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/java-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | cd05235d52ffb3318513d883a56c87a121015c8b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width