Bug 296040 - IllegalAccessError when compiling with ajc
Summary: IllegalAccessError when compiling with ajc
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: 1.6.6   Edit
Hardware: PC Windows 7
: P2 blocker (vote)
Target Milestone: 1.6.7   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-24 13:17 EST by Clément Denis CLA
Modified: 2009-11-26 18:24 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Clément Denis CLA 2009-11-24 13:17:46 EST
Consider this code, using TreeMultimap from Google Collection :

import java.util.Set;
import java.util.Map.Entry;

import com.google.common.collect.TreeMultimap;

public class ErrorClass {

	public void useGoogleCollections() {
		TreeMultimap<String, String> countResult = TreeMultimap.create();
		Set<Entry<String, String>> entries = countResult.entries();
		System.out.println(entries.size());
	}

}

If compiled with javac, this code runs fine.

If compiled with ajc, the bytecode references the class com.google.common.collect.AbstractSetMultimap, wich is package-private. So the call to countResult.entries() raises the following exception :

java.lang.IllegalAccessError: tried to access class com.google.common.collect.AbstractSetMultimap from class ErrorClass 

The attached project contains a test to reproduce it. I use maven aspectj plugin, but the problem also happens with AJDT in eclipse. There is no aspect defined in the project.

If run without any profile (mvn test), javac is used and the test runs fine.
If run with the aspectj profile (mvn -Paspectj test), ajc is used and the test fails.
Comment 1 Andrew Clement CLA 2009-11-24 13:27:59 EST
Wonder if this is JDT compiler bug - if it is, yuck
Comment 2 Andrew Clement CLA 2009-11-26 17:06:49 EST
I tried the same thing in Eclipse 3.3 - upon which AspectJ is currently based and it worked.  So I then debugged through the code in both eclipses to see where we were patching to break it.  The problem is the extra code here in ParameterizedMethodBinding.

The four lines indicated below do not exist in the eclipse 3.3 compiler - but is just something we do for AspectJ.

public MethodBinding getExactMethod(char[] selector, TypeBinding[] argumentTypes, CompilationUnitScope refScope) {
		MethodBinding mb = null;
		mb = getExactMethodBase(selector, argumentTypes, refScope);
                // rogue four lines
		if (mb==null) {
		 mb = type.getExactMethod(selector,argumentTypes,refScope);
		 if (mb != null) return new ParameterizedMethodBinding(this,mb);
		}
		return mb;
}

If those 4 are commented out, this error class compiles fine and runs.
Comment 3 Andrew Clement CLA 2009-11-26 18:24:15 EST
I believe those 4 lines were a temporary change made when we were first getting to grips with generics to get a particular generics related test to pass.  Since then we are doing things more correctly and do not require that change any more, but it has been harmless up to now.  Removed it and all 4127 tests pass just fine.  testcase and fix committed.