Community
Participate
Working Groups
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.
Wonder if this is JDT compiler bug - if it is, yuck
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.
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.