diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index 3d94be1c..8c60ac42 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java @@ -999,8 +999,8 @@ public class Codegen { private void generateConstructor(TargetConstructor constructor) { MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "", constructor.getDescriptor(), constructor.getSignature(), null); - if (!constructor.txGenerics().isEmpty()) - mv.visitAttribute(new JavaTXSignatureAttribute(constructor.getTXSignature())); + if (constructor.txGenerics() != null) + mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(constructor.getTXSignature()))); mv.visitCode(); var state = new State(null, mv, 1); @@ -1026,8 +1026,9 @@ public class Codegen { private void generateMethod(TargetMethod method) { // TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null); - if (method.txSignature() != null) - mv.visitAttribute(new JavaTXSignatureAttribute(method.getTXSignature())); + if (method.txSignature() != null) { + mv.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(method.getTXSignature()))); + } System.out.println(method.getDescriptor()); System.out.println(method.getSignature()); @@ -1058,8 +1059,8 @@ public class Codegen { generateSignature(clazz, clazz.generics()), clazz.superType() != null ? clazz.superType().getInternalName(): "java/lang/Object", clazz.implementingInterfaces().stream().map(TargetType::toSignature).toArray(String[]::new) ); - if (!clazz.txGenerics().isEmpty()) - cw.visitAttribute(new JavaTXSignatureAttribute(generateSignature(clazz, clazz.txGenerics()))); + if (clazz.txGenerics() != null) + cw.visitAttribute(new JavaTXSignatureAttribute(cw.newConst(generateSignature(clazz, clazz.txGenerics())))); clazz.fields().forEach(this::generateField); clazz.constructors().forEach(this::generateConstructor); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/JavaTXSignatureAttribute.java b/src/main/java/de/dhbwstuttgart/bytecode/JavaTXSignatureAttribute.java index cc9d1487..bd5f6028 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/JavaTXSignatureAttribute.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/JavaTXSignatureAttribute.java @@ -2,13 +2,10 @@ package de.dhbwstuttgart.bytecode; import org.objectweb.asm.*; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; - public class JavaTXSignatureAttribute extends Attribute { - final String signature; + final int signature; - protected JavaTXSignatureAttribute(String signature) { + protected JavaTXSignatureAttribute(int signature) { super("JavaTXSignature"); this.signature = signature; } @@ -17,13 +14,13 @@ public class JavaTXSignatureAttribute extends Attribute { protected Attribute read(ClassReader classReader, int offset, int length, char[] charBuffer, int codeAttributeOffset, Label[] labels) { var data = new byte[length]; System.arraycopy(classReader.b, offset, data, 0, length); - return new JavaTXSignatureAttribute(new String(data, StandardCharsets.UTF_8)); + return new JavaTXSignatureAttribute(data[0] << 8 | data[1]); } @Override protected ByteVector write(ClassWriter classWriter, byte[] code, int codeLength, int maxStack, int maxLocals) { var data = new ByteVector(); - data.putUTF8(this.signature); + data.putShort(this.signature); return data; } }