Skip to content

Skip files the Kotlin analysis cannot handle, and always exit - #1038

Open
ofir-blaus wants to merge 1 commit into
scip-code:kotlin-analysis-apifrom
ofir-blaus:kotlin-analysis-skip-unanalyzable-file
Open

ofir-blaus wants to merge 1 commit into
scip-code:kotlin-analysis-apifrom
ofir-blaus:kotlin-analysis-skip-unanalyzable-file

Conversation

@ofir-blaus

@ofir-blaus ofir-blaus commented Oct 15, 2026 •

Copy link
Copy Markdown

Small fix on top of #963.

Problem: a .kt file with a top-level destructuring declaration (val (a, b) = Pair(1, 2)) crashes the indexer with No fir element was found for KtDestructuringDeclaration. The whole run is lost. Then the process hangs instead of exiting, because a non-daemon thread keeps the JVM alive. We hit this on a test fixture in a real repo. The code is invalid Kotlin, but it can still show up in a source tree.

Reproduction: two files.

// src/Broken.kt
package repro

fun before(): Int = 1

val (first, second) = Pair(1, 2)

fun after(): Int = before()
// src/Other.kt
package repro

fun other(): Int = after()

The command, run from the folder with src/:

java -cp <scip-kotlin-analysis classpath> org.scip_code.scip_java.kotlin_analysis.MainKt \
  --sourceroot $PWD --targetroot $PWD/out src

Before (kotlin-analysis-api @ a77e133): the indexer crashes, writes no output for either file, and never exits. It was still running after 25 seconds, and the thread dump shows a non-daemon ApplicationImpl pooled thread waiting forever:

Exception in thread "main" org.jetbrains.kotlin.utils.exceptions.KotlinIllegalArgumentExceptionWithAttachments: No fir element was found for KtDestructuringDeclaration
	...
	at org.jetbrains.kotlin.analysis.api.fir.components.KaFirExpressionTypeProvider.getExpressionType(KaFirExpressionTypeProvider.kt:69)
	at org.scip_code.scip_java.kotlin_analysis.KotlinAnalysisIndexer$IndexingVisitor.renderedExpressionType(KotlinAnalysisIndexer.kt:656)
	at org.scip_code.scip_java.kotlin_analysis.KotlinAnalysisIndexer$IndexingVisitor.visitDestructuringDeclaration(KotlinAnalysisIndexer.kt:588)
	...

$ jstack <pid>   # 25s later
"ApplicationImpl pooled thread 1" #34 prio=4 ... waiting on condition
   java.lang.Thread.State: WAITING (parking)
	at java.util.concurrent.SynchronousQueue.take(SynchronousQueue.java:318)

After (this PR): exit 0 in about 1 second, with output for both files:

out/META-INF/scip/src/Broken.kt.scip
out/META-INF/scip/src/Other.kt.scip

Fix:

  • Skip a top-level destructuring declaration. The rest of the file is still indexed.
  • If indexing a file throws, skip only that file and print one line to stderr.
  • If the run fails, exit with status 1 so the process never hangs.

Tests:

  • New test: the same two files. Both are indexed, and references between them are kept.
  • :scip-kotlin-analysis:test passes, and spotlessCheck passes.
  • :scip-snapshots:test: all Kotlin snapshots pass. Locally I see 17 Java snapshot failures, but the same 17 fail on kotlin-analysis-api without this change. My local JDK is 21, not 17.

🤖 Generated with Claude Code

A top-level destructuring declaration in a .kt file (`val (a, b) = ...`)
is not valid Kotlin, so the Analysis API has no FIR for it, and asking for
its type threw "No fir element was found for KtDestructuringDeclaration".
That exception aborted the whole run. Afterwards a non-daemon pooled
thread kept the JVM alive, so the process hung instead of exiting.

- Skip a top-level destructuring declaration instead of resolving it.
- If indexing a file throws, skip that file (no shard, one line on
  stderr) and keep indexing the rest.
- Exit with status 1 when the run fails, so the process never hangs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant