NPE in `RedactedIrGenerationExtension` during `compileTestFixturesKotlin`
- Kotlin 1.7.0
- Spring Boot 2.7.1
- redacted 1.1.0
- Gradle 7.4.2
I'm trying to migrate from Sekret because of 1.7.0 support.
I did a find and replace to update the annotation, removed the Sekret plugin, and applied the redacted plugin to all subprojects (I have a multi-module Gradle project) via a buildSrc convention plugin.
However I get an NPE
e: java.lang.NullPointerException
at dev.zacsweers.redacted.compiler.RedactedIrGenerationExtension.generate(RedactedIrGenerationExtension.kt:31)
I can run gradle assemble successfully.
However when I run gradle testClasses --no-build-cache I get an exception.
There are no @Redacted annotations anywhere, except for in src/main directories - so I'm not sure what the problem is. The only guess I have is that it's something to do with the java-test-fixtures plugin?
buildSrc plugins
Kotlin JVM convention
// buildSrc/.../kotlin-jvm.gradle.kts
package buildsrc.convention
plugins {
kotlin("jvm")
`java-library`
jacoco
id("dev.zacsweers.redacted")
}
extensions.configure<dev.zacsweers.redacted.gradle.RedactedPluginExtension> {
redactedAnnotation.set("net.afanasev.sekret.Secret") // this does not affect the NPE
}
Spring Boot convention
Some subprojects are Spring Boot libraries. I'm only using kapt for the Spring Boot configuration processor. I tried disabling it though - but no change.
// buildSrc/.../spring-boot.gradle.kts
plugins {
id("org.springframework.boot")
id("buildsrc.convention.kotlin-jvm")
kotlin("plugin.spring")
kotlin("plugin.jpa")
// kotlin("kapt") // required by: spring-boot-configuration-processor
}
dependencies {
// kapt(platform(SpringBootPlugin.BOM_COORDINATES))
// annotationProcessor(platform(SpringBootPlugin.BOM_COORDINATES))
//
// kapt("org.springframework.boot:spring-boot-configuration-processor") {
// because("required by spring-boot-configuration-processor")
// }
// annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") {
// because("required by spring-boot-configuration-processor")
// }
}
Subproject config
And then in some subprojects, I have the test-fixtures plugin applied
plugins {
buildsrc.convention.`spring-boot`
`java-test-fixtures`
}
dependencies {
implementation(projects.service.core)
implementation(libs.springBoot.starterWeb)
testImplementation(testFixtures(projects.service.testLib))
testImplementation(libs.springBoot.starterTest)
testImplementation(libs.kotlinx.coroutinesTest)
testFixturesImplementation(projects.service.core)
testFixturesImplementation(libs.kotest.property)
}
Stacktrace
...
> Task :service:core:compileTestFixturesKotlin FAILED
e: java.lang.NullPointerException
at dev.zacsweers.redacted.compiler.RedactedIrGenerationExtension.generate(RedactedIrGenerationExtension.kt:31)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr$lambda-1(JvmIrCodegenFactory.kt:162)
at org.jetbrains.kotlin.psi2ir.Psi2IrTranslator.generateModuleFragment(Psi2IrTranslator.kt:99)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr(JvmIrCodegenFactory.kt:194)
at org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory.convertToIr(JvmIrCodegenFactory.kt:53)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.convertToIr(KotlinToJVMBytecodeCompiler.kt:232)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:115)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:60)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:157)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:94)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:43)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:477)
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:127)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:366)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:311)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl$rebuild(IncrementalCompilerRunner.kt:111)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:165)
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:74)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:625)
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:101)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1739)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
>
Can you make a minimally reproducing sample project? I have some familiarity with test fixtures but not enough to say if they wouldn't have access to classes in src/main