eclipse-jdt/eclipse.jdt.core

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

Open

#3.916 geöffnet am 10. Apr. 2025

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Java (183 Forks)auto 404
Modernizationgood first issuehelp wanted

Repository-Metriken

Stars
 (233 Stars)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

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

Contributor Guide