Bug 430243 - IllegalAccessError
Summary: IllegalAccessError
Status: NEW
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.7.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-12 23:55 EDT by vipin aravind CLA
Modified: 2014-03-13 12:27 EDT (History)
1 user (show)

See Also:


Attachments
Test AJ Project (24.87 MB, application/x-zip-compressed)
2014-03-13 00:07 EDT, vipin aravind CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description vipin aravind CLA 2014-03-12 23:55:42 EDT
When running the app on android, We get a IllegalAccessError runtime crash.
I have attached the AJ project that does binary weaving. woven jar:- woven.jar

Test code:-
public static boolean isIntentAvailable(Context ctx, Intent intent) {
		  final PackageManager mgr = ctx.getPackageManager();
		  List<ResolveInfo> list =
				  citrix.android.content.pm.PackageManager.queryIntentActivities((Object)mgr, intent, 
		      PackageManager.MATCH_DEFAULT_ONLY);
		  return list.size() > 0;
		}

Runtime logs:-
03-13 07:27:00.810: I/PackageManager(376): Running dexopt on: com.citrix.androidapiexerciser
03-13 07:27:01.028: I/dalvikvm(25631): DexOpt: illegal method access (call Lcom/test/PackageManagerAspect;.$SWITCH_TABLE$com$test2$PolicyProviderConstants$OpenInPolicyValues ()[I from Lcitrix/android/content/pm/PackageManager;)
03-13 07:27:01.247: D/dalvikvm(25631): DexOpt: load 95ms, verify+opt 236ms, 1105036 bytes
03-13 07:27:01.341: W/PackageManager(376): Code path for pkg : com.citrix.androidapiexerciser changing from /data/app/com.citrix.androidapiexerciser-1.apk to /data/app/com.citrix.androidapiexerciser-2.apk
03-13 07:27:01.341: I/ActivityManager(376): Force stopping package com.citrix.androidapiexerciser appid=10116 user=-1
03-13 07:27:01.341: W/PackageManager(376): Resource path for pkg : com.citrix.androidapiexerciser changing from /data/app/com.citrix.androidapiexerciser-1.apk to /data/app/com.citrix.androidapiexerciser-2.apk
03-13 07:27:01.341: W/PackageManager(376): Skipping provider name com.citrix.androidapiexerciser.MyContentProvider (in package com.citrix.androidapiexerciser): name already used by com.citrix.androidapiexerciser



03-10 15:30:26.619: W/dalvikvm(1737): threadid=1: thread exiting with uncaught exception (group=0x41af2700)
03-10 15:30:26.627: E/AndroidRuntime(1737): FATAL EXCEPTION: main
03-10 15:30:26.627: E/AndroidRuntime(1737): java.lang.IllegalAccessError: tried to access method com.citrix.APIContainment.aspects.PackageManagerAspect.$SWITCH_TABLE$com$citrix$APIContainment$policies$PolicyProviderConstants$OpenInPolicyValues:(Ljava/lang/Object;Landroid/content/Intent;ILcom/citrix/APIContainment/aspects/PackageManagerAspect;Landroid/content/Intent;ILorg/aspectj/runtime/internal/AroundClosure;)Ljava/lang/Object; from class citrix.android.content.pm.PackageManager
03-10 15:30:26.627: E/AndroidRuntime(1737): 	at citrix.android.content.pm.PackageManager.queryIntentActivities_aroundBody3$advice(Unknown Source)
03-10 15:30:26.627: E/AndroidRuntime(1737): 	at citrix.android.content.pm.PackageManager.queryIntentActivities(Unknown Source)
03-10 15:30:26.627: E/AndroidRuntime(1737): 	at com.citrix.androidapiexerciser.APIApp.isIntentAvailable(APIApp.java:65)
03-10 15
Comment 1 vipin aravind CLA 2014-03-13 00:07:59 EDT
Created attachment 240836 [details]
Test AJ Project

The attached AJ project generates the woven jar.
Comment 2 vipin aravind CLA 2014-03-13 06:38:32 EDT
When I made this synthetic method "public" by decompiling and recompiling the jar, I was able to avoid the IllegalAccessError.
I think the quick and safer fix in aspectj would be to make all the synthetic methods "public"

# direct methods
.method static synthetic $SWITCH_TABLE$com$test2$PolicyProviderConstants$OpenInPolicyValues()[I
Comment 3 Andrew Clement CLA 2014-03-13 12:02:56 EDT
The simple workaround here is to move the switch statement from the advice into a helper method:

Object around()...
  switch (foo) {
    ...
  }
}

to 

Object around()...
  compute()
}

public void compute() {
  switch (foo) {
    ...
  }
}

(but it is only a workaround).  JDT is building some of the synthetics here, it isn't just AspectJ. Normally an accessor would be generated for a method that needs raised visibility and that doesn't seem to be happening here. Making all synthetics public is probably a step too far.
Comment 4 vipin aravind CLA 2014-03-13 12:27:58 EDT
Suggested workaround of moving the body into a seperate helper method works.