Skip to content

Commit

Permalink
Fix test. Why did we use jdk.internal.misc instead of sun.misc though
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Nov 23, 2023
1 parent 08ebc83 commit e4344e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1035,10 +1035,10 @@ project(':cleanroom') {
// TODO: MDK Task

userdevConfig {
def artifacts = Util.getArtifacts(project, project.configurations.installer, true)
/*def artifacts = Util.getArtifacts(project, project.configurations.installer, true)
artifacts.each { key, lib ->
libraries.add(lib.name)
}
}*/
libraries.add('net.minecraftforge:legacydev:0.2.3.+:fatjar')
universalFilters.add('^(?!binpatches\\.pack\\.lzma$).*$')

Expand Down
20 changes: 17 additions & 3 deletions src/main/java/net/minecraftforge/registries/ObjectHolderRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
package net.minecraftforge.registries;

import java.lang.reflect.Field;
import java.lang.reflect.InaccessibleObjectException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Queue;

import com.cleanroommc.hackery.ReflectionHackery;
import jdk.internal.misc.Unsafe;
import sun.misc.Unsafe;
import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.common.FMLLog;
Expand Down Expand Up @@ -154,7 +155,17 @@ public void apply()
@SuppressWarnings("removal")
private static class FinalFieldHelper
{
private static final Unsafe unsafe=ReflectionHackery.unsafe;
private static final Unsafe unsafe;
static {
Field f;
try {
f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
unsafe = (Unsafe) f.get(null);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
static Field makeWritable(Field f) throws ReflectiveOperationException
{
f.setAccessible(true);
Expand All @@ -164,7 +175,10 @@ static Field makeWritable(Field f) throws ReflectiveOperationException

static void setField(Field field, @Nullable Object instance, Object thing) throws ReflectiveOperationException
{
field.get(instance);

try {
field.get(instance);
} catch (InaccessibleObjectException ignored) {}
unsafe.putObject(unsafe.staticFieldBase(field), unsafe.staticFieldOffset(field), thing);
}
}
Expand Down

0 comments on commit e4344e3

Please sign in to comment.