From c5c25f8fa0d943f3a22e7b43d13ef6d0e416e3fe Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Wed, 18 Dec 2024 09:28:58 +0100 Subject: [PATCH 1/2] Persisting literal values more conservativly Fixes issues with python interface files --- .../aisec/cpg/graph/statements/expressions/Literal.kt | 11 +++++++---- .../de/fraunhofer/aisec/cpg/persistence/Common.kt | 3 --- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Literal.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Literal.kt index 213e9f24b65..68a6da353bf 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Literal.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Literal.kt @@ -60,10 +60,13 @@ class Literal : Expression() { class ValueConverter : AttributeConverter { override fun toGraphProperty(value: Any?): Any? { - return if (value is BigInteger) { - value.toString() - } else { - value + // Neo4J only supports a limited set of primitive values natively, everything else, we need + // to convert to a string. + return when (value) { + (value is Number && value !is BigInteger) -> value + is Boolean -> value + null -> null + else -> value.toString() } } diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/persistence/Common.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/persistence/Common.kt index 27a25541ae6..b805d322ce3 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/persistence/Common.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/persistence/Common.kt @@ -31,7 +31,6 @@ import de.fraunhofer.aisec.cpg.graph.Persistable import de.fraunhofer.aisec.cpg.graph.edges.collections.EdgeCollection import de.fraunhofer.aisec.cpg.graph.edges.collections.EdgeList import de.fraunhofer.aisec.cpg.helpers.neo4j.NameConverter -import java.math.BigInteger import kotlin.reflect.KClass import kotlin.reflect.KProperty1 import kotlin.reflect.KTypeProjection @@ -134,8 +133,6 @@ fun Any.convert( properties.put(originalKey, this.name) } else if (this is Uuid) { properties.put(originalKey, this.toString()) - } else if (this is BigInteger) { - properties.put(originalKey, this.toString()) } else { properties.put(originalKey, this) } From b5388f9e3d16bbc6e897c1d3dc5c48b487b97d66 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Wed, 18 Dec 2024 09:31:13 +0100 Subject: [PATCH 2/2] Avoid toString() call for strings --- .../aisec/cpg/graph/statements/expressions/Literal.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Literal.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Literal.kt index 68a6da353bf..956aef7e3fc 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Literal.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/statements/expressions/Literal.kt @@ -63,9 +63,10 @@ class ValueConverter : AttributeConverter { // Neo4J only supports a limited set of primitive values natively, everything else, we need // to convert to a string. return when (value) { + null -> null (value is Number && value !is BigInteger) -> value is Boolean -> value - null -> null + is String -> value else -> value.toString() } }