Fix crash when null type references are interned
This commit is contained in:
parent
a2d0984078
commit
701def339f
|
|
@ -9,11 +9,14 @@ import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ModFileScanDataDeduplicator {
|
public class ModFileScanDataDeduplicator {
|
||||||
private final Interner<Type> typeInterner = Interners.newStrongInterner();
|
private final Interner<Type> typeInterner = Interners.newStrongInterner();
|
||||||
|
|
||||||
|
private final Function<Type, Type> internerFn = type -> type != null ? typeInterner.intern(type) : null;
|
||||||
|
|
||||||
private static Field classClazzField, parentField, interfacesField, annotationClazzField, annotationTypeField;
|
private static Field classClazzField, parentField, interfacesField, annotationClazzField, annotationTypeField;
|
||||||
private static final boolean reflectionSuccessful;
|
private static final boolean reflectionSuccessful;
|
||||||
|
|
||||||
|
|
@ -54,13 +57,13 @@ public class ModFileScanDataDeduplicator {
|
||||||
private void deduplicateClass(ModFileScanData.ClassData data) {
|
private void deduplicateClass(ModFileScanData.ClassData data) {
|
||||||
try {
|
try {
|
||||||
Type type = (Type)classClazzField.get(data);
|
Type type = (Type)classClazzField.get(data);
|
||||||
type = typeInterner.intern(type);
|
type = internerFn.apply(type);
|
||||||
classClazzField.set(data, type);
|
classClazzField.set(data, type);
|
||||||
type = (Type)parentField.get(data);
|
type = (Type)parentField.get(data);
|
||||||
type = typeInterner.intern(type);
|
type = internerFn.apply(type);
|
||||||
parentField.set(data, type);
|
parentField.set(data, type);
|
||||||
Set<Type> types = (Set<Type>)interfacesField.get(data);
|
Set<Type> types = (Set<Type>)interfacesField.get(data);
|
||||||
types = types.stream().map(typeInterner::intern).collect(Collectors.toSet());
|
types = types.stream().map(internerFn).collect(Collectors.toSet());
|
||||||
interfacesField.set(data, types);
|
interfacesField.set(data, types);
|
||||||
} catch(ReflectiveOperationException e) {
|
} catch(ReflectiveOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
@ -69,10 +72,10 @@ public class ModFileScanDataDeduplicator {
|
||||||
private void deduplicateAnnotation(ModFileScanData.AnnotationData data) {
|
private void deduplicateAnnotation(ModFileScanData.AnnotationData data) {
|
||||||
try {
|
try {
|
||||||
Type type = (Type)annotationClazzField.get(data);
|
Type type = (Type)annotationClazzField.get(data);
|
||||||
type = typeInterner.intern(type);
|
type = internerFn.apply(type);
|
||||||
annotationClazzField.set(data, type);
|
annotationClazzField.set(data, type);
|
||||||
type = (Type)annotationTypeField.get(data);
|
type = (Type)annotationTypeField.get(data);
|
||||||
type = typeInterner.intern(type);
|
type = internerFn.apply(type);
|
||||||
annotationTypeField.set(data, type);
|
annotationTypeField.set(data, type);
|
||||||
} catch(ReflectiveOperationException e) {
|
} catch(ReflectiveOperationException e) {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user