From 4175292e1973a07b29eef3e68dc39389ae401026 Mon Sep 17 00:00:00 2001 From: Evgeniy Moiseenko Date: Mon, 2 Sep 2024 15:43:27 +0200 Subject: [PATCH] =?UTF-8?q?In=20`FieldSearchHelper`=D0=B1=20skip=20protect?= =?UTF-8?q?ed=20or=20private=20fields=20that=20cannot=20be=20read=20by=20`?= =?UTF-8?q?Unsafe`=20(#367)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Signed-off-by: Evgeniy Moiseenko --- .../lincheck/strategy/managed/FieldSearchHelper.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/FieldSearchHelper.kt b/src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/FieldSearchHelper.kt index ce1f01b45..703e37a60 100644 --- a/src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/FieldSearchHelper.kt +++ b/src/jvm/main/org/jetbrains/kotlinx/lincheck/strategy/managed/FieldSearchHelper.kt @@ -60,7 +60,13 @@ internal object FieldSearchHelper { // so there is no problem that we can receive some fields of the same name and the same type. for (field in testObject::class.java.allDeclaredFieldWithSuperclasses) { if (field.type.isPrimitive) continue - val fieldValue = readFieldViaUnsafe(testObject, field, Unsafe::getObject) + + // We wrap an unsafe read into `runCatching` to hande `UnsupportedOperationException`, + // which can be thrown, for instance, when attempting to read a field of + // a hidden class (starting from Java 15). + val fieldValue = runCatching { + readFieldViaUnsafe(testObject, field, Unsafe::getObject) + }.getOrNull() ?: continue if (fieldValue in visitedObjects) continue visitedObjects += testObject