fix(decompiler): AtomicReference<V> V-parameter argument cast#3
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
当字段/局部变量类型为
AtomicReference<T>,get()返回值被读入Object局部后,再回传给compareAndSet(V, V)/getAndSet(V)/set(V)等 V 形参方法时,由于 descriptor 已将 V 擦除为 Object,反编译输出会丢掉源码中的(T)造型。javac 按泛型签名重新定型会报错:典型触发: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.gotest/cross/atomic_ref_vparam_cast_test.go(commons-lang3 AtomicInitializer)效果
commons-lang3 缺陷类 12 → 11、错误类 9 → 8,合计 97 → 96,零回归。
Made with Cursor