From c1c0731883dbd17d2dfd8c3bc8c31cb6e0c58132 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Mon, 30 Nov 2026 16:06:23 +0000 Subject: [PATCH 1/7] Support Kotlin 2.5.0 --- docs/codeql/reusables/supported-versions-compilers.rst | 2 +- .../diagnostics/kotlin-version-too-new/diagnostics.expected | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/codeql/reusables/supported-versions-compilers.rst b/docs/codeql/reusables/supported-versions-compilers.rst index 9cb146a638d1..412a37f142b5 100644 --- a/docs/codeql/reusables/supported-versions-compilers.rst +++ b/docs/codeql/reusables/supported-versions-compilers.rst @@ -21,7 +21,7 @@ Java,"Java 7 to 27 [5]_","javac (OpenJDK and Oracle JDK), Eclipse compiler for Java (ECJ) [6]_",``.java`` - Kotlin,"Kotlin 1.8.0 to 2.4.2\ *x*","kotlinc",``.kt`` + Kotlin,"Kotlin 1.8.0 to 2.5.0\ *x*","kotlinc",``.kt`` JavaScript,ECMAScript 2022 or lower,Not applicable,"``.js``, ``.jsx``, ``.mjs``, ``.es``, ``.es6``, ``.htm``, ``.html``, ``.xhtm``, ``.xhtml``, ``.vue``, ``.hbs``, ``.ejs``, ``.njk``, ``.json``, ``.yaml``, ``.yml``, ``.raml``, ``.xml`` [7]_" Python [8]_,"2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14",Not applicable,``.py`` Ruby,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``" diff --git a/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected b/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected index ff2c056ff962..96c3f1136c25 100644 --- a/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected +++ b/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected @@ -1,5 +1,5 @@ { - "markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.4.30.", + "markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.5.10.", "severity": "error", "source": { "extractorName": "java", From a0e60222ede031322896319269d9f8ca29fc6d2c Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Mon, 30 Nov 2026 16:27:23 +0000 Subject: [PATCH 2/7] Kotlin: Add 2.5.0-RC2 jars --- java/kotlin-extractor/deps/kotlin-compiler-2.5.0-RC2.jar | 3 +++ .../deps/kotlin-compiler-embeddable-2.5.0-RC2.jar | 3 +++ java/kotlin-extractor/deps/kotlin-stdlib-2.5.0-RC2.jar | 3 +++ 3 files changed, 9 insertions(+) create mode 100644 java/kotlin-extractor/deps/kotlin-compiler-2.5.0-RC2.jar create mode 100644 java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.5.0-RC2.jar create mode 100644 java/kotlin-extractor/deps/kotlin-stdlib-2.5.0-RC2.jar diff --git a/java/kotlin-extractor/deps/kotlin-compiler-2.5.0-RC2.jar b/java/kotlin-extractor/deps/kotlin-compiler-2.5.0-RC2.jar new file mode 100644 index 000000000000..0dc83ed94fc7 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-compiler-2.5.0-RC2.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:302015ffd351a1d7d2a6ef0c4e7cda88c1fa15d3da651ed6beedee9e5e5ba6b7 +size 60766544 diff --git a/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.5.0-RC2.jar b/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.5.0-RC2.jar new file mode 100644 index 000000000000..b3c6b25a83a3 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.5.0-RC2.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd5d5aac23d6d2d8ea8537464bd86fadb47dfb42b83fa24c353e37c26fe9d873 +size 59197160 diff --git a/java/kotlin-extractor/deps/kotlin-stdlib-2.5.0-RC2.jar b/java/kotlin-extractor/deps/kotlin-stdlib-2.5.0-RC2.jar new file mode 100644 index 000000000000..42e10a61a231 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-stdlib-2.5.0-RC2.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88dd3429edda2b1457d933a580e043bdcef4361a731e906b43616badfed90cd2 +size 1906670 From e712cbc2cea4639b2d3f407c062badfc34c00e2c Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Mon, 30 Nov 2026 16:52:05 +0000 Subject: [PATCH 3/7] Tell the build system about the new version --- MODULE.bazel | 3 +++ java/kotlin-extractor/versions.bzl | 1 + 2 files changed, 4 insertions(+) diff --git a/MODULE.bazel b/MODULE.bazel index c1c940ee744f..2f50375a4bca 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -324,6 +324,7 @@ use_repo( "kotlin-compiler-2.3.20", "kotlin-compiler-2.4.0", "kotlin-compiler-2.4.20", + "kotlin-compiler-2.5.0-RC2", "kotlin-compiler-embeddable-1.8.0", "kotlin-compiler-embeddable-1.9.0-Beta", "kotlin-compiler-embeddable-1.9.20-Beta", @@ -337,6 +338,7 @@ use_repo( "kotlin-compiler-embeddable-2.3.20", "kotlin-compiler-embeddable-2.4.0", "kotlin-compiler-embeddable-2.4.20", + "kotlin-compiler-embeddable-2.5.0-RC2", "kotlin-stdlib-1.8.0", "kotlin-stdlib-1.9.0-Beta", "kotlin-stdlib-1.9.20-Beta", @@ -350,6 +352,7 @@ use_repo( "kotlin-stdlib-2.3.20", "kotlin-stdlib-2.4.0", "kotlin-stdlib-2.4.20", + "kotlin-stdlib-2.5.0-RC2", ) go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") diff --git a/java/kotlin-extractor/versions.bzl b/java/kotlin-extractor/versions.bzl index 17c925493905..28c152f8f39e 100644 --- a/java/kotlin-extractor/versions.bzl +++ b/java/kotlin-extractor/versions.bzl @@ -13,6 +13,7 @@ VERSIONS = [ "2.3.20", "2.4.0", "2.4.20", + "2.5.0-RC2", ] def _version_to_tuple(v): From d135baaebffe35db75b064fa58ca7c3af8540ec1 Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Mon, 30 Nov 2026 17:08:48 +0000 Subject: [PATCH 4/7] Kotlin: Allow empty globs in get_compatilibity_sources This means the first build when adding support for a new version actually gets as far as giving a useful error message. --- java/kotlin-extractor/versions.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/kotlin-extractor/versions.bzl b/java/kotlin-extractor/versions.bzl index 28c152f8f39e..1eef44c524e2 100644 --- a/java/kotlin-extractor/versions.bzl +++ b/java/kotlin-extractor/versions.bzl @@ -43,6 +43,6 @@ def get_compatilibity_sources(version, dir): compat_version = d[len(prefix):].replace("_", ".") if version_less(version, compat_version): break - files = native.glob(["%s/*.kt" % d]) + files = native.glob(["%s/*.kt" % d], allow_empty = True) srcs |= {_basename(f): f for f in files} return srcs.values() From 6777307dd84dc53da6636bdb921b3902fe5eddfc Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Wed, 2 Dec 2026 01:35:01 +0000 Subject: [PATCH 5/7] Kotlin: Move equivalentTrap's read loop out of `use` lambdas The Kotlin 2.5 compiler no longer accepts an endless `while (true)` loop, nested inside inline `use { }` lambdas, as the end of a function returning Boolean, and reports "missing return statement". Move the line comparison loop into a helper, equivalentTrapLines, so that it is the function body itself. Behaviour is unchanged, and this compiles with all supported Kotlin versions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 38400d2f-9060-4b63-8536-73ce77bb5c91 --- .../main/kotlin/KotlinExtractorExtension.kt | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt b/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt index 9f524de737e2..af9496fc4ba4 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt @@ -331,21 +331,20 @@ This function determines whether 2 TRAP files should be considered to be equivalent. It returns `true` iff all of their non-comment lines are identical. */ -private fun equivalentTrap(r1: BufferedReader, r2: BufferedReader): Boolean { - r1.use { br1 -> - r2.use { br2 -> - while (true) { - val l1 = br1.readLine() - val l2 = br2.readLine() - if (l1 == null && l2 == null) { - return true - } else if (l1 == null || l2 == null) { - return false - } else if (l1 != l2) { - if (!l1.startsWith("//") || !l2.startsWith("//")) { - return false - } - } +private fun equivalentTrap(r1: BufferedReader, r2: BufferedReader): Boolean = + r1.use { br1 -> r2.use { br2 -> equivalentTrapLines(br1, br2) } } + +private fun equivalentTrapLines(br1: BufferedReader, br2: BufferedReader): Boolean { + while (true) { + val l1 = br1.readLine() + val l2 = br2.readLine() + if (l1 == null && l2 == null) { + return true + } else if (l1 == null || l2 == null) { + return false + } else if (l1 != l2) { + if (!l1.startsWith("//") || !l2.startsWith("//")) { + return false } } } From 6bc5f568d6c0bb9390645ca29f9a60e196268bde Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Wed, 2 Dec 2026 01:36:11 +0000 Subject: [PATCH 6/7] Kotlin: Support compiler API changes in 2.5.0-RC2 Kotlin 2.5 removed `JvmCodegenUtil` and `IrPluginContext.moduleDescriptor`, and `IrExternalPackageFragmentImpl` now needs an `IrModuleFragment`. Add two compatibility functions, with the previous behaviour in v_1_8_0 and the new one in v_2_5_0-RC2: - getCurrentJvmModuleName, used by KotlinUsesExtractor.getJvmModuleName for the name of the module being compiled. For 2.5 it applies the old JvmCodegenUtil.getModuleName logic to the module fragment's descriptor. KotlinExtractorGlobalState now holds the module fragment to support this. - createExternalPackageFragment, used to make the synthetic `kotlin.internal.ir` package for RawTypeAnnotation. For 2.5 it passes IrErrorModuleFragment, as the compiler's own JvmIrSpecialAnnotationSymbolProvider does. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 38400d2f-9060-4b63-8536-73ce77bb5c91 --- .../src/main/kotlin/KotlinExtractorExtension.kt | 4 ++-- .../src/main/kotlin/KotlinUsesExtractor.kt | 3 +-- .../src/main/kotlin/utils/TypeSubstitution.kt | 3 +-- .../v_1_8_0/createExternalPackageFragment.kt | 11 +++++++++++ .../versions/v_1_8_0/getCurrentJvmModuleName.kt | 14 ++++++++++++++ .../createExternalPackageFragment.kt | 16 ++++++++++++++++ .../v_2_5_0-RC2/getCurrentJvmModuleName.kt | 17 +++++++++++++++++ 7 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/createExternalPackageFragment.kt create mode 100644 java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/getCurrentJvmModuleName.kt create mode 100644 java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/createExternalPackageFragment.kt create mode 100644 java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/getCurrentJvmModuleName.kt diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt b/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt index af9496fc4ba4..b1a5f43d346b 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt @@ -164,7 +164,7 @@ class KotlinExtractorExtension( } ?: "kotlin-extractor/src" ) srcDir.mkdirs() - val globalExtensionState = KotlinExtractorGlobalState() + val globalExtensionState = KotlinExtractorGlobalState(moduleFragment) moduleFragment.files.mapIndexed { index: Int, file: IrFile -> val fileExtractionProblems = FileExtractionProblems(invocationExtractionProblems) val fileTrapWriter = tw.makeSourceFileTrapWriter(file, true) @@ -264,7 +264,7 @@ class KotlinExtractorExtension( } } -class KotlinExtractorGlobalState { +class KotlinExtractorGlobalState(val moduleFragment: IrModuleFragment) { // These three record mappings of classes, functions and fields that should be replaced wherever // they are found. // As of now these are only used to fix IR generated by the Gradle Android Extensions plugin, diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt index b3577858f99c..2ea5d2e09f56 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt @@ -6,7 +6,6 @@ import com.semmle.extractor.java.OdasaOutput import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext import org.jetbrains.kotlin.backend.common.ir.* import org.jetbrains.kotlin.backend.jvm.ir.* -import org.jetbrains.kotlin.codegen.JvmCodegenUtil import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* @@ -1055,7 +1054,7 @@ open class KotlinUsesExtractor( private fun getJvmModuleName(f: IrFunction) = NameUtils.sanitizeAsJavaIdentifier( getJvmModuleNameForDeserializedDescriptor(f.descriptor) - ?: JvmCodegenUtil.getModuleName(pluginContext.moduleDescriptor) + ?: getCurrentJvmModuleName(pluginContext, globalExtensionState.moduleFragment) ) fun getFunctionShortName(f: IrFunction): FunctionNames { diff --git a/java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt b/java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt index c990edc213f6..9045647ef1bc 100644 --- a/java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt +++ b/java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.builders.declarations.buildClass import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrTypeParameter import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer -import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.impl.* @@ -177,7 +176,7 @@ object RawTypeAnnotation { val annotationConstructor: IrConstructorCall by lazy { val irInternalPackage = FqName("kotlin.internal.ir") val parent = - IrExternalPackageFragmentImpl( + createExternalPackageFragment( DescriptorlessExternalPackageFragmentSymbol(), irInternalPackage ) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/createExternalPackageFragment.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/createExternalPackageFragment.kt new file mode 100644 index 000000000000..72cae61f3596 --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/createExternalPackageFragment.kt @@ -0,0 +1,11 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment +import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl +import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol +import org.jetbrains.kotlin.name.FqName + +fun createExternalPackageFragment( + symbol: IrExternalPackageFragmentSymbol, + fqName: FqName +): IrExternalPackageFragment = IrExternalPackageFragmentImpl(symbol, fqName) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/getCurrentJvmModuleName.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/getCurrentJvmModuleName.kt new file mode 100644 index 000000000000..33f5702fb0ba --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/getCurrentJvmModuleName.kt @@ -0,0 +1,14 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.codegen.JvmCodegenUtil +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrModuleFragment + +@OptIn(ObsoleteDescriptorBasedAPI::class) +@Suppress("UNUSED_PARAMETER") +fun getCurrentJvmModuleName( + pluginContext: IrPluginContext, + moduleFragment: IrModuleFragment +): String = + JvmCodegenUtil.getModuleName(pluginContext.moduleDescriptor) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/createExternalPackageFragment.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/createExternalPackageFragment.kt new file mode 100644 index 000000000000..156ada1e9ccc --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/createExternalPackageFragment.kt @@ -0,0 +1,16 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment +import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl +import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol +import org.jetbrains.kotlin.ir.util.IrErrorModuleFragment +import org.jetbrains.kotlin.name.FqName + +// The fragment now needs a module. As in the compiler's own +// `JvmIrSpecialAnnotationSymbolProvider`, a placeholder module is sufficient for the synthetic +// packages we create. +fun createExternalPackageFragment( + symbol: IrExternalPackageFragmentSymbol, + fqName: FqName +): IrExternalPackageFragment = + IrExternalPackageFragmentImpl(symbol, fqName, IrErrorModuleFragment) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/getCurrentJvmModuleName.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/getCurrentJvmModuleName.kt new file mode 100644 index 000000000000..0ea4e45e5f7d --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/getCurrentJvmModuleName.kt @@ -0,0 +1,17 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrModuleFragment + +// `JvmCodegenUtil` and `IrPluginContext.moduleDescriptor` no longer exist, so this mirrors what +// `JvmCodegenUtil.getModuleName(pluginContext.moduleDescriptor)` used to do. +@OptIn(ObsoleteDescriptorBasedAPI::class) +@Suppress("UNUSED_PARAMETER") +fun getCurrentJvmModuleName( + pluginContext: IrPluginContext, + moduleFragment: IrModuleFragment +): String { + val module = moduleFragment.descriptor + return (module.stableName ?: module.name).asString().removeSurrounding("<", ">") +} From 2a4d37b6f20d18c50503a5cad41b2e7fb38b030c Mon Sep 17 00:00:00 2001 From: Ian Lynagh Date: Wed, 2 Dec 2026 01:37:20 +0000 Subject: [PATCH 7/7] Kotlin: Add changenote for 2.5.0 support --- java/ql/lib/change-notes/2026-11-30-kotlin-2.5.0.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 java/ql/lib/change-notes/2026-11-30-kotlin-2.5.0.md diff --git a/java/ql/lib/change-notes/2026-11-30-kotlin-2.5.0.md b/java/ql/lib/change-notes/2026-11-30-kotlin-2.5.0.md new file mode 100644 index 000000000000..7f56919ffcf3 --- /dev/null +++ b/java/ql/lib/change-notes/2026-11-30-kotlin-2.5.0.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* Support for Kotlin 2.5.0 has been added.