mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-28 04:07:01 -05:00
Fix NPE in AnnotationsApplyVisitor (#1371)
* Fix NPE in AnnotationsApplyVisitor * Fix test
This commit is contained in:
@@ -46,31 +46,34 @@ import net.fabricmc.tinyremapper.api.TrClass;
|
||||
public record AnnotationsApplyVisitor(AnnotationsData annotationsData) implements TinyRemapper.ApplyVisitorProvider {
|
||||
@Override
|
||||
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) {
|
||||
return new AnnotationsApplyClassVisitor(next, cls.getName(), annotationsData);
|
||||
ClassAnnotationData classData = annotationsData.classes().get(cls.getName());
|
||||
|
||||
if (classData == null) {
|
||||
return next;
|
||||
}
|
||||
|
||||
return new AnnotationsApplyClassVisitor(next, classData);
|
||||
}
|
||||
|
||||
public static class AnnotationsApplyClassVisitor extends ClassVisitor {
|
||||
private final ClassAnnotationData classData;
|
||||
private boolean hasAddedAnnotations;
|
||||
|
||||
public AnnotationsApplyClassVisitor(ClassVisitor cv, String className, AnnotationsData annotationsData) {
|
||||
public AnnotationsApplyClassVisitor(ClassVisitor cv, ClassAnnotationData classData) {
|
||||
super(Constants.ASM_VERSION, cv);
|
||||
this.classData = annotationsData.classes().get(className);
|
||||
this.classData = classData;
|
||||
hasAddedAnnotations = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
if (classData != null) {
|
||||
access = classData.modifyAccessFlags(access);
|
||||
}
|
||||
|
||||
access = classData.modifyAccessFlags(access);
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
||||
if (classData != null && classData.typeAnnotationsToRemove().contains(new TypeAnnotationKey(typeRef, typePath.toString(), Type.getType(descriptor).getInternalName()))) {
|
||||
if (classData.typeAnnotationsToRemove().contains(new TypeAnnotationKey(typeRef, typePath.toString(), Type.getType(descriptor).getInternalName()))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -79,7 +82,7 @@ public record AnnotationsApplyVisitor(AnnotationsData annotationsData) implement
|
||||
|
||||
@Override
|
||||
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||
if (classData != null && classData.annotationsToRemove().contains(Type.getType(descriptor).getInternalName())) {
|
||||
if (classData.annotationsToRemove().contains(Type.getType(descriptor).getInternalName())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@ class AnnotationsApplyTest extends Specification {
|
||||
def annotationData = AnnotationsData.read(new StringReader(ANNOTATIONS_DATA))
|
||||
|
||||
def annotatedNode1 = new ClassNode()
|
||||
def classVisitor1 = new AnnotationsApplyVisitor.AnnotationsApplyClassVisitor(annotatedNode1, 'net/fabricmc/loom/test/unit/processor/AnnotationsApplyTest$ExampleClass1', annotationData)
|
||||
def classVisitor1 = new AnnotationsApplyVisitor.AnnotationsApplyClassVisitor(annotatedNode1, annotationData.classes().get('net/fabricmc/loom/test/unit/processor/AnnotationsApplyTest$ExampleClass1'))
|
||||
def annotatedNode2 = new ClassNode()
|
||||
def classVisitor2 = new AnnotationsApplyVisitor.AnnotationsApplyClassVisitor(annotatedNode2, 'net/fabricmc/loom/test/unit/processor/AnnotationsApplyTest$ExampleClass2', annotationData)
|
||||
def classVisitor2 = new AnnotationsApplyVisitor.AnnotationsApplyClassVisitor(annotatedNode2, annotationData.classes().get('net/fabricmc/loom/test/unit/processor/AnnotationsApplyTest$ExampleClass2'))
|
||||
|
||||
when:
|
||||
def classReader1 = new ClassReader(getClassBytes(ExampleClass1))
|
||||
|
||||
Reference in New Issue
Block a user