Resolve "ACC_DEPRECATED flag (or corresponding attribute) is lost if the constant pool is copied"
There is a generic way to implement the same thing, which would automatically ensure that this logic is always up to date:
boolean canCopyMethodAttributes(
final int access,
final String name,
final String descriptor,
final String signature,
final String[] exceptions,
final ClassReader source,
final int sourceOffset,
final int sourceLength) {
if (symbolTable.getSource() == source) {
MethodWriter sourceWriter =
new MethodWriter(
symbolTable, access, name, descriptor, signature, exceptions, COMPUTE_NOTHING);
int methodInfoSize = computeMethodInfoSize();
if (methodInfoSize == sourceWriter.computeMethodInfoSize()) {
ByteVector byteVector = new ByteVector(methodInfoSize * 2);
putMethodInfo(byteVector);
sourceWriter.putMethodInfo(byteVector);
for (int i = 6; i < methodInfoSize; ++i) {
if (byteVector.data[i] != byteVector.data[i + methodInfoSize]) {
return false;
}
}
this.sourceOffset = sourceOffset;
this.sourceLength = sourceLength;
return true;
}
}
return false;
}
However, the benchmarks showed this is about 10% slower than the current (buggy) implementation for an optimized transform with the 'copyPool' option. I thus kept the current implementation method (with the bugs fixed), and added a test to make sure this method is updated (if needed) when new attributes are defined.
Closes #317822 (closed) Closes #317824 (closed)
Edited by Eric Bruneton