[Tests] ClassFileBytesDisassembler based tests should not encode constant pool index
#3,916 opened on Apr 10, 2025
Repository metrics
- Stars
- (233 stars)
- PR merge metrics
- (PR metrics pending)
Description
As the evolving PR https://github.com/eclipse-jdt/eclipse.jdt.core/pull/3896 shows, it is very painful when tests encode disassembly output. The said PR results in a different order of methods emission in the class file that results in constant pool indexes that are hard coded in the tests to be invalidated and for many tests to "fail" - It is only the constant pool index that differs, the indexed entry is still the same.
It would be good to avoid encoding disassembly into tests unless absolutely needed instead relying on reflection or runtime behavior where possible.
Where we must rely on disassembly,
- We need to come up with a new mode for
ClassFileBytesDisassemblerthat elides constant pool indexes in the ouput - Ensure somehow (via deprecation or ...) that no new tests get written that would encode the numerical index.
In a disassembly output like, there is absolutely nothing to be achieved by encoding constant pool offsets (shown in **index** form below)
// Method descriptor **#34** (Ljava/util/List;)V
// Signature: (Ljava/util/List<Ljava/lang/String;>;)V
// Stack: 2, Locals: 2
Record(java.util.List list);
0 aload_0 [this]
1 invokespecial java.lang.Record() [**36**]
4 aload_0 [this]
5 aload_1 [list]
6 putfield Record.list : java.util.List [**14**]
9 return
Line numbers:
[pc: 0, line: 1]
Method Parameters:
list
RuntimeVisibleTypeAnnotations:
#**10** @Ann(
target type = 0x16 METHOD_FORMAL_PARAMETER
method parameter index = 0
)
#**10** @Ann(
target type = 0x16 METHOD_FORMAL_PARAMETER
method parameter index = 0
location = [TYPE_ARGUMENT(0)]
)
;