The JDK 21 compiler linter flags potential `this-escape` violations in DGS generated code
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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