Skip to content

fix(decompiler): AtomicReference<V> V-parameter argument cast#3

Merged
VillanCh merged 1 commit into
mainfrom
fix/atomic-ref-vparam-cast
Jul 7, 2026
Merged

fix(decompiler): AtomicReference<V> V-parameter argument cast#3
VillanCh merged 1 commit into
mainfrom
fix/atomic-ref-vparam-cast

Conversation

@VillanCh

@VillanCh VillanCh commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

问题

当字段/局部变量类型为 AtomicReference<T>get() 返回值被读入 Object 局部后,再回传给 compareAndSet(V, V) / getAndSet(V) / set(V) 等 V 形参方法时,由于 descriptor 已将 V 擦除为 Object,反编译输出会丢掉源码中的 (T) 造型。javac 按泛型签名重新定型会报错:

Object cannot be converted to T

典型触发:commons-lang3 AtomicInitializer<T>.get() 中的 this.reference.compareAndSet(null, var1)

修复

jdkMethodParamTypeArgIndex 中新增 AtomicReference 分支:V 是唯一类型实参,将相关方法的 V 形参位映射到类型实参索引 0,复用既有的 instantiatedParamType + arg-cast 路径重新下发 (T) unchecked 造型。

覆盖的方法:

  • compareAndSet(V, V) / weakCompareAndSet(V, V)(argc==2,两形参)
  • getAndSet(V) / set(V) / lazySet(V)(argc==1,形参 0)
  • getAndAccumulate(V, BinaryOperator<V>) / accumulateAndGet(V, BinaryOperator<V>)(argc==2,仅形参 0)

ntype==1(裸/非通配参数化 AtomicReference<V>),通配 AtomicReference<?> 维持原有早退。Kill-switch:JDEC_ATOMIC_REF_PARAM_OFF

测试

  • 单元承重:classparser/atomic_ref_vparam_test.go
  • 真实 jar 回归:test/cross/atomic_ref_vparam_cast_test.go(commons-lang3 AtomicInitializer)

效果

commons-lang3 缺陷类 12 → 11、错误类 9 → 8,合计 97 → 96,零回归。

Made with Cursor

In JDK method parameter type-arg index table, add AtomicReference branch:
compareAndSet/weakCompareAndSet (both params), getAndSet/set/lazySet,
and getAndAccumulate/accumulateAndGet (first param) resolve their V
parameter to the receiver's type arg. This lets the existing arg-cast
path re-emit the source (T) unchecked cast and prevents javac from
rejecting a bare Object argument as "Object cannot be converted to T".

Load-bearing tests:
- classparser/atomic_ref_vparam_test.go
- test/cross/atomic_ref_vparam_cast_test.go (commons-lang3 AtomicInitializer)

Switch: JDEC_ATOMIC_REF_PARAM_OFF. Fixes commons-lang3 1 case; total
defects 97 -> 96, classes 9 -> 8, zero regression.

Co-authored-by: Cursor <cursoragent@cursor.com>
@VillanCh VillanCh merged commit 315d22e into main Jul 7, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant