TNG / ArchUnit

A Java architecture test library, to specify and assert architecture rules in plain Java
http://archunit.org
Apache License 2.0
3.17k stars 287 forks source link

Unable to find the JavaAccess call #1262

Closed heyuxiang1996 closed 5 months ago

heyuxiang1996 commented 5 months ago

When opening this class file with jadx, it will be found that hasNextNotification has been called, but the corresponding call cannot be found with archunit HistoryLoader.json Changing the JSON file suffix to "class" is the corresponding class file

heyuxiang1996 commented 5 months ago

Perhaps it's because the jar package I converted using APK does not conform to the basic format of the jar package?

heyuxiang1996 commented 5 months ago

Does it mean that only archunit can scan the freshest compiled class or jar package files?

hankem commented 5 months ago

The class file import currently only considers files whose name ends with .class – also when importing class files from a jar.

Why would the byte code of com.android.settings.notification.history.HistoryLoader end up in a HistoryLoader.json file?

heyuxiang1996 commented 5 months ago

The class file import currently only considers files whose name ends with .class – also when importing class files from a jar.

Why would the byte code of com.android.settings.notification.history.HistoryLoader end up in a HistoryLoader.json file?

Github does not allow uploading class files, so I changed the suffix to upload

heyuxiang1996 commented 5 months ago

This class file is part of the jar package

heyuxiang1996 commented 5 months ago

HistoryLoader.json This class file is the same as the previous class file opened with jadx, but scanning with the getAccessesFromSelf() method of archunit is completely different

heyuxiang1996 commented 5 months ago

Perhaps the jar package converted using APK is not compliant, I just want to confirm this issue 🙈

hankem commented 5 months ago

Sorry for my initial confusion about the .json file!

ArchUnit 0.23.1 would have found JavaMethodCall{origin=JavaMethod{com.android.settings.notification.history.HistoryLoader.lambda$load$2(com.android.settings.notification.history.HistoryLoader$OnHistoryLoaderListener)}, target=target{android.app.NotificationHistory.hasNextNotification()}, lineNumber=17}

but #889 tries to map accesses by synthetic methods such as this one from your HistoryLoader.class:

  private void lambda$load$2(com.android.settings.notification.history.HistoryLoader$OnHistoryLoaderListener);
    descriptor: (Lcom/android/settings/notification/history/HistoryLoader$OnHistoryLoaderListener;)V
    flags: (0x1002) ACC_PRIVATE, ACC_SYNTHETIC

Since ArchUnit 1.0.0, importing your HistoryLoader.class gives a warning similar to this:

WARN com.tngtech.archunit.core.importer.ClassFileImportRecord - Could not find matching origin for synthetic method RawAccessRecord{origin=CodeUnit{name='lambda$load$2', descriptor=(Lcom/android/settings/notification/history/HistoryLoader$OnHistoryLoaderListener;)V, declaringClassName='com.android.settings.notification.history.HistoryLoader'}, target=TargetInfo{owner='android.app.NotificationHistory', name='hasNextNotification', desc='()Z'}, lineNumber=24, declaredInLambda=false}