This is an automated email from the ASF dual-hosted git repository.
wernerdv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 376bd3a0d67 IGNITE-28849 Fix GridTestUtils.setFieldValue on JDK 21
(#13320)
376bd3a0d67 is described below
commit 376bd3a0d6757335d110f1d29be89eec641b3b3d
Author: Aleksandr Nikolaev <[email protected]>
AuthorDate: Wed Sep 23 18:22:39 2026 +0300
IGNITE-28849 Fix GridTestUtils.setFieldValue on JDK 21 (#13320)
---
.../apache/ignite/testframework/GridTestUtils.java | 46 +---------------------
1 file changed, 2 insertions(+), 44 deletions(-)
diff --git
a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
index 21b2765fe8b..c624cc8ba22 100644
---
a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
+++
b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java
@@ -23,8 +23,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.VarHandle;
import java.lang.management.ManagementFactory;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
@@ -1770,35 +1768,10 @@ public final class GridTestUtils {
*/
public static void setFieldValue(Object obj, String fieldName, Object val)
throws IgniteException {
assert obj != null;
- assert fieldName != null;
- try {
- Class<?> cls = obj instanceof Class ? (Class)obj : obj.getClass();
+ Class<?> cls = obj instanceof Class ? (Class)obj : obj.getClass();
- Field field = cls.getDeclaredField(fieldName);
-
- boolean isFinal = (field.getModifiers() & Modifier.FINAL) != 0;
-
- boolean isStatic = (field.getModifiers() & Modifier.STATIC) != 0;
-
- /**
- *
http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.5.3
- * If a final field is initialized to a compile-time constant in
the field declaration,
- * changes to the final field may not be observed.
- */
- if (isFinal && isStatic)
- throw new IgniteException("Modification of static final field
through reflection.");
-
- boolean accessible = field.isAccessible();
-
- if (!accessible)
- field.setAccessible(true);
-
- field.set(obj, val);
- }
- catch (NoSuchFieldException | IllegalAccessException e) {
- throw new IgniteException("Failed to set object field [obj=" + obj
+ ", field=" + fieldName + ']', e);
- }
+ setFieldValue(obj, cls, fieldName, val);
}
/**
@@ -1833,21 +1806,6 @@ public final class GridTestUtils {
if (isFinal && isStatic)
throw new IgniteException("Modification of static final field
through reflection.");
- if (isFinal && U.majorJavaVersion(U.jdkVersion()) >= 12) {
- MethodHandles.Lookup lookup =
MethodHandles.privateLookupIn(Field.class, MethodHandles.lookup());
-
- VarHandle varHandle = lookup.findVarHandle(Field.class,
"modifiers", int.class);
-
- varHandle.set(field, field.getModifiers() & ~Modifier.FINAL);
- }
- else if (isFinal) {
- Field modifiersField =
Field.class.getDeclaredField("modifiers");
-
- modifiersField.setAccessible(true);
-
- modifiersField.setInt(field, field.getModifiers() &
~Modifier.FINAL);
- }
-
field.set(obj, val);
}
catch (NoSuchFieldException | IllegalAccessException e) {