Skip to content

Commit b468a42

Browse files
authored
Use ClassId name in prettifiedName if canonical name is null (#484)
1 parent c08c780 commit b468a42

File tree

1 file changed

+13
-6
lines changed
  • utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api

1 file changed

+13
-6
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,21 @@ open class ClassId(
642642
open val simpleName: String get() = jClass.simpleName
643643

644644
/**
645-
* For regular classes this is just a simple name
646-
* For anonymous classes this includes the containing class and numeric indices of the anonymous class
645+
* For regular classes this is just a simple name.
646+
* For anonymous classes this includes the containing class and numeric indices of the anonymous class.
647+
*
648+
* Note: according to [java.lang.Class.getCanonicalName] documentation, local and anonymous classes
649+
* do not have canonical names, as well as arrays whose elements don't have canonical classes themselves.
650+
* In these cases prettified names are constructed using [ClassId.name] instead of [ClassId.canonicalName].
647651
*/
648652
val prettifiedName: String
649-
get() = canonicalName
650-
.substringAfterLast(".")
651-
.replace(Regex("[^a-zA-Z0-9]"), "")
652-
.let { if (this.isArray) it + "Array" else it }
653+
get() {
654+
val className = jClass.canonicalName ?: name // Explicit jClass reference to get null instead of exception
655+
return className
656+
.substringAfterLast(".")
657+
.replace(Regex("[^a-zA-Z0-9]"), "")
658+
.let { if (this.isArray) it + "Array" else it }
659+
}
653660

654661
open val packageName: String get() = jClass.`package`?.name ?: "" // empty package for primitives
655662

0 commit comments

Comments
 (0)