From 18c718ea9689160949beb411596f7c37749e49f9 Mon Sep 17 00:00:00 2001 From: shifujun Date: Tue, 18 Apr 2023 18:08:13 +0800 Subject: [PATCH] =?UTF-8?q?fix(core.transform):=20=E8=AF=86=E5=88=AB?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=86onReceive=E6=96=B9=E6=B3=95=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E6=97=B6=EF=BC=8C=E6=8E=92=E9=99=A4=E9=9D=99=E6=80=81?= =?UTF-8?q?=E5=86=85=E9=83=A8=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 静态内部类getDeclaredMethod时能获取到父类定义的方法, 但它带有Volatile标志位。 --- .../specific/ReceiverSupportTransform.kt | 8 ++++-- .../src/test/java/test/EggReceiver.java | 27 +++++++++++++++++++ .../specific/ReceiverSupportTransformTest.kt | 2 ++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 projects/sdk/core/transform/src/test/java/test/EggReceiver.java diff --git a/projects/sdk/core/transform/src/main/kotlin/com/tencent/shadow/core/transform/specific/ReceiverSupportTransform.kt b/projects/sdk/core/transform/src/main/kotlin/com/tencent/shadow/core/transform/specific/ReceiverSupportTransform.kt index 79bfbc2ea..f5a324fe7 100644 --- a/projects/sdk/core/transform/src/main/kotlin/com/tencent/shadow/core/transform/specific/ReceiverSupportTransform.kt +++ b/projects/sdk/core/transform/src/main/kotlin/com/tencent/shadow/core/transform/specific/ReceiverSupportTransform.kt @@ -20,7 +20,11 @@ package com.tencent.shadow.core.transform.specific import com.tencent.shadow.core.transform_kit.SpecificTransform import com.tencent.shadow.core.transform_kit.TransformStep -import javassist.* +import javassist.CodeConverter +import javassist.CtClass +import javassist.CtMethod +import javassist.Modifier +import javassist.NotFoundException import javassist.compiler.Javac.CtFieldWithInit /** @@ -70,7 +74,7 @@ class ReceiverSupportTransform : SpecificTransform() { } catch (e: NotFoundException) { null } - if (onReceiveMethod != null) { + if (onReceiveMethod != null && !Modifier.isVolatile(onReceiveMethod.modifiers)) { targetReceivers.add(ctClass) } } diff --git a/projects/sdk/core/transform/src/test/java/test/EggReceiver.java b/projects/sdk/core/transform/src/test/java/test/EggReceiver.java new file mode 100644 index 000000000..851f80fed --- /dev/null +++ b/projects/sdk/core/transform/src/test/java/test/EggReceiver.java @@ -0,0 +1,27 @@ +package test; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import java.util.List; + +abstract class EggReceiver extends BroadcastReceiver { + List log; + + EggReceiver(List log) { + this.log = log; + } + + @Override + public void onReceive(Context context, Intent intent) { + log.add("EggReceiver onReceive"); + } + + public static class FoxReceiver extends EggReceiver { + FoxReceiver(List log) { + super(log); + } + } + +} diff --git a/projects/sdk/core/transform/src/test/kotlin/com/tencent/shadow/core/transform/specific/ReceiverSupportTransformTest.kt b/projects/sdk/core/transform/src/test/kotlin/com/tencent/shadow/core/transform/specific/ReceiverSupportTransformTest.kt index 9e15aa860..8eabf8b27 100644 --- a/projects/sdk/core/transform/src/test/kotlin/com/tencent/shadow/core/transform/specific/ReceiverSupportTransformTest.kt +++ b/projects/sdk/core/transform/src/test/kotlin/com/tencent/shadow/core/transform/specific/ReceiverSupportTransformTest.kt @@ -21,6 +21,8 @@ class ReceiverSupportTransformTest : AbstractTransformTest() { "test.BarReceiver", "test.CatReceiver", "test.DogReceiver", + "test.EggReceiver", + "test.EggReceiver\$FoxReceiver", ) ].toMutableSet()