diff options
author | LexManos <LexManos@gmail.com> | 2021-05-26 10:46:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-26 10:46:53 -0700 |
commit | 578f33b206c7325762a956a1f3e3171d5c6d9052 (patch) | |
tree | 22e8db707b69b433463446b0709f93a6df65c27f /src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java | |
parent | 12aeb6f4c7c09e749204707475a7f71b16c14133 (diff) | |
parent | c3948938178810000353830671e474abb9d32a2c (diff) | |
download | Artifactural-578f33b206c7325762a956a1f3e3171d5c6d9052.tar.gz Artifactural-578f33b206c7325762a956a1f3e3171d5c6d9052.tar.bz2 Artifactural-578f33b206c7325762a956a1f3e3171d5c6d9052.zip |
Remove JDK reflection hacks in favor of `Unsafe`
Merge pull request #4 from sciwhiz12/theUnsafe
Diffstat (limited to 'src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java')
-rw-r--r-- | src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java index 4e18885..1c8cdac 100644 --- a/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java +++ b/src/gradlecomp/java/net/minecraftforge/artifactural/gradle/ReflectionUtils.java @@ -19,8 +19,11 @@ package net.minecraftforge.artifactural.gradle; +import net.minecraftforge.fml.unsafe.UnsafeHacks; + import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.function.UnaryOperator; public class ReflectionUtils { @@ -39,7 +42,11 @@ public class ReflectionUtils { T oldV = (T)f.get(target); T newV = operator.apply(oldV); - f.set(target, newV); + if (Modifier.isFinal(f.getModifiers())) { + UnsafeHacks.setField(f, target, newV); + } else { + f.set(target, newV); + } if (f.get(target) != newV) { throw new IllegalStateException("Failed to set new value on " + f.getDeclaringClass().getName() + "." + f.getName()); @@ -68,9 +75,6 @@ public class ReflectionUtils { for (Field f : clazz.getDeclaredFields()) { if (f.getName().equals(name)) { f.setAccessible(true); - 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; } } |