eclipse-jdt/eclipse.jdt.core

[Tests] ClassFileBytesDisassembler based tests should not encode constant pool index

Open

#3,916 创建于 2025年4月10日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)Java (183 fork)auto 404
Modernizationgood first issuehelp wanted

仓库指标

Star
 (233 star)
PR 合并指标
 (PR 指标待抓取)

描述

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 ClassFileBytesDisassembler that 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)]
      )
;

贡献者指南