Netflix / Netflix/dgs-codegen

The JDK 21 compiler linter flags potential `this-escape` violations in DGS generated code

Open
#651 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
217
Forks
116
PR merge metrics
No merged PRs in 30d

Description

When compiling code generated by dgs-codegen using JDK 21 and having all linters enabled using the -Xlint:all compiler argument, then the compiler will raise a warning of a potential this-escape in some generated code.

I've created a minimal reproduction case for a violation in the constructor of a Mutation query, see: https://github.com/Badbond/dgs-codegen-reproduction-case-this-escape. We have also seen the issue being raised for a similar case in a Projection using a static initializer:

public class StateMachineFragmentProjection<PARENT extends BaseSubProjectionNode<?, ?>, ROOT extends BaseSubProjectionNode<?, ?>> extends BaseSubProjectionNode<PARENT, ROOT> {
  {
    getFields().put("__typename", null);
  }

  public StateMachineFragmentProjection(PARENT parent, ROOT root) {
    super(parent, root, java.util.Optional.of("StateMachine"));
  }

See also JDK-8299995.

Environment:

  • Maven 3.9.5.
  • JDK 21.0.2-tem.
  • DGS codegen 6.1.3.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated Mutation constructor and Projection initializer, reproducing the warning with JDK 21 and -Xlint:all using the linked minimal case. Trace both outputs back through dgs-codegen; done when the generated code no longer raises the reported this-escape warning in either example.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.