aboutsummaryrefslogtreecommitdiff
path: root/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java')
-rw-r--r--src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java31
1 files changed, 2 insertions, 29 deletions
diff --git a/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java b/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java
index d3078d5..9ee484c 100644
--- a/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java
+++ b/src/gradlecomp/java/com/amadornes/artifactural/gradle/ReflectionUtils.java
@@ -22,6 +22,7 @@ package com.amadornes.artifactural.gradle;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.util.function.Function;
import java.util.function.UnaryOperator;
public class ReflectionUtils {
@@ -69,7 +70,7 @@ public class ReflectionUtils {
for (Field f : clazz.getDeclaredFields()) {
if (f.getName().equals(name)) {
f.setAccessible(true);
- if (!definalize(f)) {
+ if (!ModifierAccess.definalize(f)) {
System.out.println("Could not definalize field " + f.getDeclaringClass().getName() + "." + f.getName() + " Exception ate, lets see if it works");
}
return f;
@@ -80,34 +81,6 @@ public class ReflectionUtils {
return null;
}
- private static Field MODIFIER_ACCESS = null;
- private static boolean accessAttempted = false;
- private static synchronized boolean definalize(Field f) {
- if ((f.getModifiers() & Modifier.FINAL) == 0) {
- return true;
- }
-
- if (MODIFIER_ACCESS == null && !accessAttempted) {
- try {
- Field modifiers = Field.class.getDeclaredField("modifiers");
- modifiers.setAccessible(true);
- MODIFIER_ACCESS = modifiers;
- } catch (NoSuchFieldException e) {
- System.out.println("Could not access Field.modifiers to definalize reflection object. This happens on JVMs > 12, going to see if things work, if not use JVM 8-11");
- }
- accessAttempted = true;
- }
- if (MODIFIER_ACCESS != null) {
- try {
- MODIFIER_ACCESS.setInt(f, f.getModifiers() & ~Modifier.FINAL);
- } catch (IllegalArgumentException | IllegalAccessException e) {
- throw new RuntimeException("Could not definalize field " + f.getDeclaringClass().getName() + "." + f.getName(), e);
- }
- return true;
- }
- return false;
- }
-
/**
* Invokes a method (can be private).
*/