From 6b1597534241f624c8ce79ddcd6e96f59083f459 Mon Sep 17 00:00:00 2001 From: Dmitrii Timofeev Date: Mon, 11 Jul 2022 14:57:26 +0300 Subject: [PATCH 1/2] Use ClassId name in prettifiedName if canonical name is null --- .../main/kotlin/org/utbot/framework/plugin/api/Api.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index be42ca8e4b..063c71dead 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -646,10 +646,13 @@ open class ClassId( * For anonymous classes this includes the containing class and numeric indices of the anonymous class */ val prettifiedName: String - get() = canonicalName - .substringAfterLast(".") - .replace(Regex("[^a-zA-Z0-9]"), "") - .let { if (this.isArray) it + "Array" else it } + get() { + val className = jClass.canonicalName ?: name // Explicit jClass reference to get null instead of exception + return className + .substringAfterLast(".") + .replace(Regex("[^a-zA-Z0-9]"), "") + .let { if (this.isArray) it + "Array" else it } + } open val packageName: String get() = jClass.`package`?.name ?: "" // empty package for primitives From 7216a8d63a8d4bd99cc5a53af7c4ffa4beca8a72 Mon Sep 17 00:00:00 2001 From: Dmitrii Timofeev Date: Mon, 11 Jul 2022 17:57:44 +0300 Subject: [PATCH 2/2] Updated documentation for `ClassId.prettifiedName` --- .../src/main/kotlin/org/utbot/framework/plugin/api/Api.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 063c71dead..19f9af113f 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -642,8 +642,12 @@ open class ClassId( open val simpleName: String get() = jClass.simpleName /** - * For regular classes this is just a simple name - * For anonymous classes this includes the containing class and numeric indices of the anonymous class + * For regular classes this is just a simple name. + * For anonymous classes this includes the containing class and numeric indices of the anonymous class. + * + * Note: according to [java.lang.Class.getCanonicalName] documentation, local and anonymous classes + * do not have canonical names, as well as arrays whose elements don't have canonical classes themselves. + * In these cases prettified names are constructed using [ClassId.name] instead of [ClassId.canonicalName]. */ val prettifiedName: String get() {