Improve GraphQL/DGS layer for Java 17 compatibility#552
Open
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
Open
Improve GraphQL/DGS layer for Java 17 compatibility#552devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
Conversation
- Replace double-brace HashMap initialization with Map.of() in ArticleDatafetcher and CommentDatafetcher (avoids unnecessary anonymous inner classes, uses immutable maps) - Fix raw type cast in GraphQLCustomizeExceptionHandler.errorsToMap() by adding proper generic type parameter - Modernize Map population with computeIfAbsent() replacing containsKey()+put() pattern in GraphQLCustomizeExceptionHandler - Extract ConstraintViolationException to local variable in onException() to eliminate repeated casting Co-Authored-By: shayan <shayan@cognition.ai>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Code modernization of the GraphQL/DGS layer to eliminate problematic patterns and use modern Java APIs (Java 9–11), verified to compile cleanly on JDK 17.
Changes:
Map.of()inArticleDatafetcher(3 sites) andCommentDatafetcher(1 site). Double-brace init creates anonymous inner class subclasses of HashMap on every call, which is wasteful and can cause subtle serialization/memory issues.Map.of()returns a compact, immutable map.GraphQLCustomizeExceptionHandler.errorsToMap()—(List)→(List<String>)with a scoped@SuppressWarnings("unchecked").containsKey()+put()withcomputeIfAbsent()in bothgetErrorsAsDataanderrorsToMapmethods.ConstraintViolationExceptionto a local variable inonException()to eliminate repeated inline casting ofhandlerParameters.getException().Review & Testing Checklist for Human
Map.of()immutability is safe: The originalHashMapwas mutable;Map.of()is unmodifiable. Confirm that no downstream DGS data fetcher or framework code mutates thelocalContextmap. The child fetchers (ProfileDatafetcher.getAuthor(),CommentDatafetcher.articleComments()) appear to only call.get(), but runtime verification is important../gradlew test) to validate no behavioral regressions — the Spotless formatter has a pre-existing incompatibility with JDK 17, sospotlessCheckwill fail independently of these changes.computeIfAbsentequivalence inerrorsToMap: The return type isMap<String, Object>but values are alwaysArrayList<String>— verify the unchecked cast path is safe.Notes
instanceofpattern matching (Java 16+) was considered but cannot be used becausebuild.gradlesetssourceCompatibility = '11'. UpgradingsourceCompatibility/targetCompatibilityto'17'(and the DGS codegen plugin to 6.x+) would unlock further modernization but is out of scope per task constraints.DataFetcherExceptionHandler.onException()method is deprecated in graphql-java 17.x in favor ofhandleException()returningCompletableFuture. This is a pre-existing issue tied to the DGS 4.x / Spring Boot 2.6.x versions and not addressed here.javax.validationimports are correct for Spring Boot 2.6.x; migration tojakarta.validationwould only be needed alongside a Spring Boot 3.x upgrade.Link to Devin session: https://app.devin.ai/sessions/571f3f1add874782bfb8c4e91030b38e
Requested by: @shayanshafii