Skip to content

Commit 971b1f0

Browse files
committed
Bump cafedude to address LVT ASM crash
1 parent bedf178 commit 971b1f0

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ assertj = "3.27.3"
44
asm = "9.8"
55
atlantafx = "2.0.1"
66
binary-resources = "31.3.0-alpha01.8"
7-
cafedude = "2.6.1"
7+
cafedude = "2.6.2"
88
cdi-api = "4.1.0"
99
cdi-impl = "6.0.2.Final"
1010
cfr = "0.152"

recaf-core/src/main/java/software/coley/recaf/info/builder/JvmClassInfoBuilder.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,16 @@ public JvmClassInfoBuilder adaptFrom(@Nonnull ClassReader reader, int flags) {
227227
// If we are doing validation checks, delegating the reader to a writer should catch most issues
228228
// that would normally crash ASM. It is the caller's responsibility to error handle ASM failing
229229
// if such failures occur.
230-
adapter = new ClassBuilderAdapter(skipValidationChecks ? null : new ClassWriter(reader, 0));
231-
reader.accept(adapter, flags);
230+
if (skipValidationChecks) {
231+
adapter = new ClassBuilderAdapter(null);
232+
reader.accept(adapter, flags);
233+
} else {
234+
ClassWriter cw = new ClassWriter(reader, 0);
235+
adapter = new ClassBuilderAdapter(cw);
236+
reader.accept(adapter, flags);
237+
cw.toByteArray();
238+
}
239+
232240
return withBytecode(reader.b);
233241
}
234242

@@ -388,7 +396,8 @@ public void visitAttribute(Attribute attribute) {
388396

389397
@Override
390398
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
391-
return new FieldBuilderAdapter(access, name, descriptor, signature, value) {
399+
FieldVisitor fv = super.visitField(access, name, descriptor, signature, value);
400+
return new FieldBuilderAdapter(fv, access, name, descriptor, signature, value) {
392401

393402
@Override
394403
public void visitAttribute(Attribute attribute) {
@@ -401,13 +410,15 @@ public void visitEnd() {
401410
if (fields == null)
402411
fields = new ArrayList<>();
403412
fields.add(getFieldMember());
413+
super.visitEnd();
404414
}
405415
};
406416
}
407417

408418
@Override
409419
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
410-
return new MethodBuilderAdapter(access, name, descriptor, signature, exceptions) {
420+
MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions);
421+
return new MethodBuilderAdapter(mv, access, name, descriptor, signature, exceptions) {
411422

412423
@Override
413424
public void visitAttribute(Attribute attribute) {
@@ -477,9 +488,9 @@ public Collection<String> getCustomAttributeNames() {
477488
private static class FieldBuilderAdapter extends FieldVisitor {
478489
private final BasicFieldMember fieldMember;
479490

480-
public FieldBuilderAdapter(int access, String name, String descriptor,
491+
public FieldBuilderAdapter(FieldVisitor fv, int access, String name, String descriptor,
481492
String signature, Object value) {
482-
super(getAsmVersion());
493+
super(getAsmVersion(), fv);
483494
fieldMember = new BasicFieldMember(name, descriptor, signature, access, value);
484495
}
485496

@@ -507,9 +518,9 @@ private static class MethodBuilderAdapter extends MethodVisitor {
507518
private int parameterIndex;
508519
private int parameterSlot;
509520

510-
public MethodBuilderAdapter(int access, String name, String descriptor,
521+
public MethodBuilderAdapter(MethodVisitor mv, int access, String name, String descriptor,
511522
String signature, String[] exceptions) {
512-
super(getAsmVersion());
523+
super(getAsmVersion(), mv);
513524
List<String> exceptionList = exceptions == null ? Collections.emptyList() : Arrays.asList(exceptions);
514525
methodMember = new BasicMethodMember(name, descriptor, signature, access, exceptionList);
515526
methodDescriptor = Type.getMethodType(descriptor);
@@ -529,7 +540,8 @@ public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, Str
529540

530541
@Override
531542
public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index) {
532-
methodMember.addLocalVariable(new BasicLocalVariable(index, name, descriptor, signature));
543+
if (name != null && descriptor != null)
544+
methodMember.addLocalVariable(new BasicLocalVariable(index, name, descriptor, signature));
533545
super.visitLocalVariable(name, descriptor, signature, start, end, index);
534546
}
535547

0 commit comments

Comments
 (0)