Fix @QueryProjection constructor generation for Kotlin value classes (@JvmInline)#1762
Merged
velo merged 2 commits intoMay 27, 2026
Merged
Conversation
When a DTO annotated with @QueryProjection has constructor parameters of Kotlin value class types (@JvmInline), the APT processor failed to generate a constructor in the Q-type because ExtendedTypeFactory could not resolve the value class to a QueryDSL path type. Fix by detecting @JvmInline annotated classes in createClassType() and unwrapping them to their single underlying field type before type resolution. Also add null guard in TypeElementHandler.getType() as a defensive measure.
velo
approved these changes
May 27, 2026
…n-kotlin-value-class # Conflicts: # querydsl-tooling/querydsl-apt/src/test/java/com/querydsl/apt/QuerydslAnnotationProcessorCompileTest.java
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.
Problem
When a DTO annotated with
@QueryProjectionhas constructor parameters of Kotlin value class (@JvmInline) types, the APT processor fails to generate a constructor in the Q-type.Reproducer:
Expected:
QUserDtois generated with a constructor acceptingExpression<String>Actual:
QUserDtois generated without a constructorRoot Cause
In
ExtendedTypeFactory.createClassType(), Kotlin value classes are treated as opaque class types.TypeCategory.get(name)returnsTypeCategory.SIMPLEfor them, but there is no registered mapping from the value class type (e.g.UserId) to a QueryDSL path type (e.g.StringPath), so type resolution returnsnull.By contrast,
@Entityfields work correctly because the Kotlin compiler exposes them at the JVM field level as their underlying type (e.g.String).Note: This issue was already fixed for KSP codegen in #1404. This PR applies the same fix to the APT/kapt processor.
Fix
ExtendedTypeFactory: Detect@JvmInline-annotated classes increateClassType()and unwrap them to the type of their single underlying field before type resolution.TypeElementHandler: Add a null guard ingetType(VariableElement)as a defensive measure.Test
Added
queryProjection_withKotlinValueClassParameter_generatesConstructor()toQuerydslAnnotationProcessorCompileTestusing the existinggoogle/compile-testinginfrastructure. The test verifies thatQUserDtois generated with a constructor acceptingExpression<String>when the DTO uses a@JvmInlinevalue class parameter.