Closed heyuxiang1996 closed 9 months ago
I am using version 1.2 of archUnit
Thanks for reporting the issue! I've started to look at your byte code and saw that the failure during the class file import
java.lang.IllegalStateException:
Never found a JavaCodeUnit that matches supposed origin CodeUnit{
name='access$084',
descriptor=(Lcom/transsion/auto/bluetooth/BluetoothUtils;Ljava/lang/Object;)Ljava/lang/String;,
declaringClassName='com.transsion.auto.bluetooth.BluetoothUtils'
}
seems to be caused by
BluetoothUtils
's synthetic method access$084
BluetoothUtils$1
's method onReceive
)I need to look deeper into the problem, but already want to ask:
BluetoothUtils.java
(maybe it's enough to include the private field dev_mac_address
and the code that uses the anonymous android.content.BroadcastReceiver
)?This is my Java file. The class file is an intermediate product of compiling APK using Gradle
It's the same problem as in #1146, which occurs when inner classes use +=
on a private String
field of the outer class.
Minimal example:
class Outer {
private String privateString = "";
class Inner {
void method() {
privateString += "+";
}
}
}
Some compiler( configuration)s, e.g. OpenJDK 11 with -source 8 -target 8
, may produce a synthetic method that uses a StringBuilder
, which ArchUnit at the moment unfortunately cannot handle correctly:
static java.lang.String access$084(Outer, java.lang.Object);
descriptor: (LOuter;Ljava/lang/Object;)Ljava/lang/String;
flags: (0x1008) ACC_STATIC, ACC_SYNTHETIC
Code:
stack=3, locals=2, args_size=2
0: new #1 // class java/lang/StringBuilder
3: dup
4: invokespecial #2 // Method java/lang/StringBuilder."<init>":()V
7: aload_0
8: dup_x1
9: getfield #3 // Field privateString:Ljava/lang/String;
12: invokevirtual #4 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
15: aload_1
16: invokevirtual #5 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
19: invokevirtual #6 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
22: dup_x1
23: putfield #3 // Field privateString:Ljava/lang/String;
26: areturn
@heyuxiang1996, as a workaround, you can probably replace your dev_mac_address += device.getAddress();
with dev_mac_address = dev_mac_address + device.getAddress();
.