Skip to content

Commit e0fce9e

Browse files
committed
Fixed check on computeIfAbsent
1 parent 0da8d4a commit e0fce9e

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

cache/cache-symbol-processor/src/main/kotlin/io/koraframework/cache/symbol/processor/CacheSymbolProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class CacheSymbolProcessor(
357357
)
358358

359359
val keyName = "_key" + (i + 1)
360-
keyBuilder.addStatement("val %L = %L.apply(key.%L!!)!!", keyName, mapperName, recordField.simpleName.asString())
360+
keyBuilder.addStatement("val %L = %L.apply(key!!.%L!!)!!", keyName, mapperName, recordField.simpleName.asString())
361361
if (i == 0) {
362362
compositeKeyBuilder.add("val _compositeKey = %T(", ByteArray::class)
363363
for (j in recordFields.indices) {

cache/cache-symbol-processor/src/main/kotlin/io/koraframework/cache/symbol/processor/aop/CacheableAopKoraAspect.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,23 @@ class CacheableAopKoraAspect(private val resolver: Resolver) : AbstractAopCacheA
4949
val superMethod = getSuperMethod(method, superCall)
5050
val builder = CodeBlock.builder()
5151

52+
val isResultNullable = method.returnType!!.resolve().isMarkedNullable
53+
val suffixCheck = if (isResultNullable) "" else "!!"
5254
if (operation.executions.size == 1) {
5355
val keyBlock = CodeBlock.of("val _key = %L\n", operation.executions[0].cacheKey!!.code)
5456
val isSingleNullableParam = operation.executions[0].type.isMarkedNullable
5557
val codeBlock = if (isSingleNullableParam) {
5658
CodeBlock.of(
5759
"""
5860
return if (_key != null) {
59-
%L.computeIfAbsent(_key) { %L }
61+
%L.computeIfAbsent(_key) { %L }%L
6062
} else {
6163
%L
6264
}
63-
""".trimIndent(), operation.executions[0].field, superMethod, superMethod
65+
""".trimIndent(), operation.executions[0].field, superMethod, suffixCheck, superMethod
6466
)
6567
} else {
66-
CodeBlock.of("return %L.computeIfAbsent(_key) { %L }", operation.executions[0].field, superMethod)
68+
CodeBlock.of("return %L.computeIfAbsent(_key) { %L }%L", operation.executions[0].field, superMethod, suffixCheck)
6769
}
6870

6971
return CodeBlock.builder()

0 commit comments

Comments
 (0)