Kotlin: make KDoc-section PCE rethrow portable across compiler versions

The KDoc-section parser added for the K2/FIR frontend caught
`com.intellij.openapi.progress.ProcessCanceledException` by type in order to
rethrow it (a control-flow exception that must never be swallowed) before the
general `catch (Exception)` fallback.

That compile-time type reference is not resolvable on every supported Kotlin
compiler version: the IntelliJ classes bundled in the compiler-embeddable
classpath vary across the versions in `versions.bzl`. It compiled under 2.3.20
and 2.4.0 (so the language-test builds were green) but failed the internal
extractor build with `unresolved reference 'ProcessCanceledException'`.

Match the exception by class name instead of by type. This keeps the exact
same behaviour (the cancellation exception is still rethrown, everything else
is logged and yields null) while removing the only compile-time reference to a
class that is not present on every version's classpath. Verified the standalone
extractor now builds for 1.9.20-Beta, 2.0.0-RC1 and 2.4.0.

No expected-output changes: the runtime behaviour is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Anders Fugmann
2026-07-14 09:03:59 +02:00
parent 4e3a2f6d33
commit 97199fdc39

View File

@@ -66,9 +66,15 @@ class CommentExtractorLighterAST(
org.jetbrains.kotlin.kdoc.psi.api.KDoc::class.java
)
kdoc?.getAllSections()
} catch (e: com.intellij.openapi.progress.ProcessCanceledException) {
throw e
} catch (e: Exception) {
// Never swallow IntelliJ's ProcessCanceledException: it is a control-flow
// exception that must propagate for cancellation to work. We match it by
// name rather than by type because the class is not resolvable on every
// supported compiler version (its embeddable classpath varies), and a
// compile-time reference breaks the cross-version build.
if (e.javaClass.name == "com.intellij.openapi.progress.ProcessCanceledException") {
throw e
}
logger.warn("Couldn't parse KDoc sections: ${e}")
null
}