Skip to content

fix(ksp): skip parameterized supertypes in TypeExtractor.fallbackType()#1690

Open
bangbang93 wants to merge 1 commit intoOpenFeign:masterfrom
bangbang93:fix/ksp-parameterized-supertypes
Open

fix(ksp): skip parameterized supertypes in TypeExtractor.fallbackType()#1690
bangbang93 wants to merge 1 commit intoOpenFeign:masterfrom
bangbang93:fix/ksp-parameterized-supertypes

Conversation

@bangbang93
Copy link
Copy Markdown

Problem

TypeExtractor.fallbackType() crashes with IllegalStateException when processing MongoDB @Document classes with ObjectId fields. The function was calling toClassName() on parameterized supertypes like Comparable<ObjectId>, which throws an exception because KotlinPoet's toClassName() doesn't support parameterized types.

Solution

Added a guard to check supertype.arguments.isEmpty() before calling toClassName() in the Comparable check. This skips parameterized supertypes like Comparable<ObjectId> which cannot be converted.

Changes

  • File: querydsl-tooling/querydsl-ksp-codegen/src/main/kotlin/com/querydsl/ksp/codegen/TypeExtractor.kt
  • Change: Added supertype.arguments.isEmpty() && guard in fallbackType() method

Testing

  • All 10 existing tests in querydsl-ksp-codegen pass
  • Minimal one-line change, no API changes or breaking changes
  • Backward compatible

Fixes #1688

TypeExtractor.fallbackType() crashed with IllegalStateException when processing
MongoDB @document classes with ObjectId fields. The function was calling
toClassName() on Comparable<ObjectId>, a parameterized type which is not
supported by KotlinPoet's toClassName().

Fix: Check supertype.arguments.isEmpty() before calling toClassName() to skip
parameterized supertypes in the Comparable check.

Fixes OpenFeign#1688

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 14, 2026 05:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a KSP crash in TypeExtractor.fallbackType() when encountering parameterized supertypes (e.g., Comparable<ObjectId>) that cannot be converted via KotlinPoet’s toClassName().

Changes:

  • Adds a guard to skip parameterized supertypes before calling toClassName() while checking for Comparable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +69 to +70
// Skip parameterized types (e.g. Comparable<ObjectId>) — toClassName() throws for them
supertype.arguments.isEmpty() && comparableNames.contains(supertype.toClassName().canonicalName)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

The new supertype.arguments.isEmpty() guard prevents Comparable<T> (which is almost always parameterized) from ever being recognized as comparable. That avoids the crash, but it also changes behavior: types like ObjectId : Comparable<ObjectId> will now be treated as SimpleType.Simple (SimplePath) instead of SimpleType.Comparable (ComparablePath), likely reducing supported comparison operators.

Instead of skipping parameterized supertypes, compare using the supertype declaration (e.g., supertype.declaration.qualifiedName?.asString() or supertype.declaration.toClassName().canonicalName) so you can safely detect Comparable regardless of type arguments without calling toClassName() on the KSType itself.

Suggested change
// Skip parameterized types (e.g. Comparable<ObjectId>) — toClassName() throws for them
supertype.arguments.isEmpty() && comparableNames.contains(supertype.toClassName().canonicalName)
comparableNames.contains(supertype.declaration.qualifiedName?.asString())

Copilot uses AI. Check for mistakes.
Comment on lines +69 to +70
// Skip parameterized types (e.g. Comparable<ObjectId>) — toClassName() throws for them
supertype.arguments.isEmpty() && comparableNames.contains(supertype.toClassName().canonicalName)
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

This change fixes a crash scenario around parameterized supertypes, but there is no regression test covering fallbackType() with a type that implements Comparable<T> (e.g., MongoDB ObjectId). Adding a focused unit/integration test that exercises TypeExtractor.fallbackType() for a parameterized Comparable supertype would prevent reintroducing the toClassName() IllegalStateException and ensure the resulting QPropertyType is correct.

Suggested change
// Skip parameterized types (e.g. Comparable<ObjectId>) — toClassName() throws for them
supertype.arguments.isEmpty() && comparableNames.contains(supertype.toClassName().canonicalName)
val supertypeDeclaration = supertype.declaration as? KSClassDeclaration
val qualifiedName = supertypeDeclaration?.qualifiedName?.asString()
comparableNames.contains(qualifiedName)

Copilot uses AI. Check for mistakes.
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.

KSP: TypeExtractor crashes on parameterized supertypes (ObjectId with MongoDB)

2 participants