From 47ed6dcfb4a13fac81a25af3d252b66bba36eef7 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Wed, 12 Jan 2022 19:25:00 +0100 Subject: [PATCH] CompilerArgumentsSerializerV5.serializeTo: fix NPE NPE was happening on `?.takeIf { it.get(arguments) != it.get(newInstance) }` line. It was happening because `it.get` could return `null`. But the problem was only reproducible on TeamCity and not reproducible locally. Test example (IJ repo): `org.jetbrains.kotlin.idea.fir.completion.HighLevelJvmBasicCompletionTestGenerated$Common$FromSmart.testArrayLiteralAnnotationConstructorAsDefaultValueForArray` stacktrace: ``` java.lang.NullPointerException at org.jetbrains.kotlin.arguments.CompilerArgumentsSerializerV5.serializeTo(CompilerArgumentsSerializer.kt:23) at org.jetbrains.kotlin.config.FacetSerializationKt.writeLatestConfig(facetSerialization.kt:379) at org.jetbrains.kotlin.config.FacetSerializationKt.serializeFacetSettings(facetSerialization.kt:422) at org.jetbrains.kotlin.idea.facet.KotlinFacetConfigurationImpl.writeExternal(KotlinFacetConfigurationImpl.kt:24) ``` --- .../jetbrains/kotlin/arguments/CompilerArgumentsSerializer.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsSerializer.kt b/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsSerializer.kt index 7d8d73cc8d0..6ed05b200e3 100644 --- a/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsSerializer.kt +++ b/jps/jps-common/src/org/jetbrains/kotlin/arguments/CompilerArgumentsSerializer.kt @@ -19,7 +19,7 @@ class CompilerArgumentsSerializerV5(override val argume val newInstance = arguments::class.java.getConstructor().newInstance() val flagArgumentsByName = CompilerArgumentsContentProspector.getFlagCompilerArgumentProperties(arguments::class) .mapNotNull { prop -> - prop.safeAs>() + prop.safeAs>() ?.takeIf { it.get(arguments) != it.get(newInstance) } ?.get(arguments) ?.let { prop.name to it }