rules_kotlin icon indicating copy to clipboard operation
rules_kotlin copied to clipboard

When strict kotlin deps is set to warn, build fails with FileNotFoundException on a JDK path

Open arunkumar9t2 opened this issue 3 years ago • 4 comments

When I try to disable strict deps the build fails with following exception.

SEVERE: Compilation failure: compile phase failed:
exception: java.io.UncheckedIOException: java.io.FileNotFoundException: /private/var/<redacted>/9f2930d169b651fc4026a3d396084f70/external/remotejdk11_macos (Is a directory)
        at io.bazel.kotlin.builder.utils.jars.JarOwner$Companion.readJarOwnerFromManifest(JarOwner.kt:24)
        at io.bazel.kotlin.plugin.jdeps.JdepsGenExtension.checkStrictDeps(JdepsGenExtension.kt:338)
        at io.bazel.kotlin.plugin.jdeps.JdepsGenExtension.doStrictDeps(JdepsGenExtension.kt:321)
        at io.bazel.kotlin.plugin.jdeps.JdepsGenExtension.analysisCompleted(JdepsGenExtension.kt:256)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:108)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:125)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:93)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:557)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:83)
        at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:548)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:192)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:162)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:169)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:88)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
        at io.bazel.kotlin.compiler.BazelK2JVMCompiler.exec(BazelK2JVMCompiler.kt:30)
        at jdk.internal.reflect.GeneratedMethodAccessor92.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.bazel.kotlin.builder.toolchain.KotlinToolchain$KotlinCliToolInvoker.compile(KotlinToolchain.kt:189)
        at io.bazel.kotlin.builder.tasks.jvm.Compilation_taskKt$compileKotlin$1$2.invoke(compilation_task.kt:299)
        at io.bazel.kotlin.builder.tasks.jvm.Compilation_taskKt$compileKotlin$1$2.invoke(compilation_task.kt)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.executeCompilerTask(CompilationTaskContext.kt:122)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.executeCompilerTask$default(CompilationTaskContext.kt:118)
        at io.bazel.kotlin.builder.tasks.jvm.Compilation_taskKt.compileKotlin(compilation_task.kt:299)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor$execute$1$$special$$inlined$apply$lambda$1.invoke(KotlinJvmTaskExecutor.kt:62)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor$execute$1$$special$$inlined$apply$lambda$1.invoke(KotlinJvmTaskExecutor.kt:33)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.execute(CompilationTaskContext.kt:148)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.execute(CompilationTaskContext.kt:140)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor$execute$1.invoke(KotlinJvmTaskExecutor.kt:60)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor$execute$1.invoke(KotlinJvmTaskExecutor.kt:33)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.execute(CompilationTaskContext.kt:148)
        at io.bazel.kotlin.builder.toolchain.CompilationTaskContext.execute(CompilationTaskContext.kt:140)
        at io.bazel.kotlin.builder.tasks.jvm.KotlinJvmTaskExecutor.execute(KotlinJvmTaskExecutor.kt:56)
        at io.bazel.kotlin.builder.tasks.KotlinBuilder.executeJvmTask(KotlinBuilder.kt:232)
        at io.bazel.kotlin.builder.tasks.KotlinBuilder.build(KotlinBuilder.kt:130)
        at io.bazel.kotlin.builder.tasks.CompileKotlin.invoke(CompileKotlin.kt:27)
        at io.bazel.worker.PersistentWorker$compileWork$2$result$1.invoke(PersistentWorker.kt:98)
        at io.bazel.worker.PersistentWorker$compileWork$2$result$1.invoke(PersistentWorker.kt:56)
        at io.bazel.worker.WorkerContext$TaskContext.resultOf(WorkerContext.kt:125)
        at io.bazel.worker.WorkerContext.doTask(WorkerContext.kt:153)
        at io.bazel.worker.PersistentWorker$compileWork$2.invokeSuspend(PersistentWorker.kt:96)
        at io.bazel.worker.PersistentWorker$compileWork$2.invoke(PersistentWorker.kt)
        at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
        at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:165)
        at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
        at io.bazel.worker.PersistentWorker.compileWork(PersistentWorker.kt:95)
        at io.bazel.worker.PersistentWorker$start$1$$special$$inlined$use$lambda$1$1$2.invokeSuspend(PersistentWorker.kt:75)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Caused by: java.io.FileNotFoundException: /private/var/tmp/<redacted>/external/remotejdk11_macos (Is a directory)
        at java.base/java.io.RandomAccessFile.open0(Native Method)
        at java.base/java.io.RandomAccessFile.open(RandomAccessFile.java:345)
        at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:259)
        at java.base/java.io.RandomAccessFile.<init>(RandomAccessFile.java:214)
        at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1271)
        at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1237)
        at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:727)
        at java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:844)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:247)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:177)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:346)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:317)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:283)
        at io.bazel.kotlin.builder.utils.jars.JarOwner$Companion.readJarOwnerFromManifest(JarOwner.kt:14)
        ... 56 more

In BUILD.bazel

define_kt_toolchain(
    name = "kotlin_toolchain",
    api_version = "1.4",
    experimental_use_abi_jars = False,
    javac_options = "//:kt_javac_options",
    experimental_strict_kotlin_deps = "warn",
    jvm_target = "1.8",
    kotlinc_options = "//:kt_kotlinc_options",
    language_version = "1.4",
)

rules_kotlin version: eae21653baad4b403fee9e8a706c9d4fbd0c27c6

I had a look at JdepsGenExtension and it seems we need to check against directory here before passing the keys to readJarOwnerManifest?

val missingStrictDeps = result.keys
      .filter { !directDeps.contains(it) }
      .map { JarOwner.readJarOwnerFromManifest(Paths.get(it)).label }

arunkumar9t2 avatar Apr 03 '21 15:04 arunkumar9t2

Changing missingStrictDeps calculation to

 val missingStrictDeps = result.keys
      .asSequence()
      .filter { !directDeps.contains(it) }
      .map { Paths.get(it) }
      .filter { !Files.isDirectory(it) }
      .map { JarOwner.readJarOwnerFromManifest(it).label }
      .toList()

allows me to compile but I am not sure why JDK directory lands here.

arunkumar9t2 avatar Apr 03 '21 16:04 arunkumar9t2

Some (just Maven maybe?) dependencies also end up here with a null label - I had the issue with the coroutines-core-jvm artifact. Which results in a command suggesting to add null to the deps of a target.

Kernald avatar May 12 '21 04:05 Kernald

For now, we're not going to be prioritizing this in advance of 1.5. We should fix it, but it is on an experimental feature, so we may not get it in for 1.5.

Experimental strict deps is still experimental because it falls afoul of a kotlinc bug with abi generation. This bug should increase in priority in advance of making it non-experimental.

cgruber avatar Aug 06 '21 19:08 cgruber

Hi, what is the status of bugfix for that? Still actual.

neckbosov avatar Oct 03 '23 11:10 neckbosov