http-api: allow gsoning classes outside of net.runelite

This broke plugin hub plugins using our gson, which is valid since you
can reflect into any unnamed module.
This commit is contained in:
Max Weber
2021-02-06 12:00:48 -07:00
committed by Adam
parent dd14ce3a4f
commit 5de258310a

View File

@@ -27,13 +27,26 @@ package net.runelite.http.api.gson;
import com.google.gson.ExclusionStrategy; import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes; import com.google.gson.FieldAttributes;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;
public class IllegalReflectionExclusion implements ExclusionStrategy public class IllegalReflectionExclusion implements ExclusionStrategy
{ {
private static final Set<ClassLoader> PRIVATE_CLASSLOADERS = new HashSet<>();
static
{
for (ClassLoader cl = ClassLoader.getSystemClassLoader(); cl != null; )
{
cl = cl.getParent();
PRIVATE_CLASSLOADERS.add(cl);
}
}
@Override @Override
public boolean shouldSkipField(FieldAttributes f) public boolean shouldSkipField(FieldAttributes f)
{ {
if (f.getDeclaringClass().getName().startsWith("net.runelite")) if (!PRIVATE_CLASSLOADERS.contains(f.getDeclaringClass().getClassLoader()))
{ {
return false; return false;
} }