Skip to content

Improve GraphQL/DGS layer for Java 17 compatibility#552

Open
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin/1776282012-java17-graphql-compat
Open

Improve GraphQL/DGS layer for Java 17 compatibility#552
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin/1776282012-java17-graphql-compat

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Apr 15, 2026

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:

  • Replace double-brace HashMap initialization with Map.of() in ArticleDatafetcher (3 sites) and CommentDatafetcher (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.
  • Fix raw type cast in GraphQLCustomizeExceptionHandler.errorsToMap()(List)(List<String>) with a scoped @SuppressWarnings("unchecked").
  • Replace containsKey()+put() with computeIfAbsent() in both getErrorsAsData and errorsToMap methods.
  • Extract ConstraintViolationException to a local variable in onException() to eliminate repeated inline casting of handlerParameters.getException().

Review & Testing Checklist for Human

  • Verify Map.of() immutability is safe: The original HashMap was mutable; Map.of() is unmodifiable. Confirm that no downstream DGS data fetcher or framework code mutates the localContext map. The child fetchers (ProfileDatafetcher.getAuthor(), CommentDatafetcher.articleComments()) appear to only call .get(), but runtime verification is important.
  • Run the full test suite (./gradlew test) to validate no behavioral regressions — the Spotless formatter has a pre-existing incompatibility with JDK 17, so spotlessCheck will fail independently of these changes.
  • Confirm computeIfAbsent equivalence in errorsToMap: The return type is Map<String, Object> but values are always ArrayList<String> — verify the unchecked cast path is safe.

Notes

  • instanceof pattern matching (Java 16+) was considered but cannot be used because build.gradle sets sourceCompatibility = '11'. Upgrading sourceCompatibility/targetCompatibility to '17' (and the DGS codegen plugin to 6.x+) would unlock further modernization but is out of scope per task constraints.
  • The DataFetcherExceptionHandler.onException() method is deprecated in graphql-java 17.x in favor of handleException() returning CompletableFuture. This is a pre-existing issue tied to the DGS 4.x / Spring Boot 2.6.x versions and not addressed here.
  • javax.validation imports are correct for Spring Boot 2.6.x; migration to jakarta.validation would only be needed alongside a Spring Boot 3.x upgrade.

Link to Devin session: https://app.devin.ai/sessions/571f3f1add874782bfb8c4e91030b38e
Requested by: @shayanshafii


Open with Devin

- 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>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown
Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant