[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Getting IllegalAccessError when using anonymous class
|
Hi,
I'm trying to convert OCL constraints into executable AspectJ code. A
special problem is caused when transforming the iterator sort(exp) into
Java code that sorts a collection according to a given expression. I
transform the expression into a java.util.Comparator which is
initialized by using an anonymous class (see code below):
package testpackage.constraints;
/**
* <p>Generated Aspect to enforce OCL constraint.</p>
*
* @author OCL22Java of Dresden OCL2 for Eclipse
* @Generated
*/
public privileged aspect Class1_DefAspect_testSortedByIteratorExp01 {
/**
* <p>Defines the method testSortedByIteratorExp01() defined by the
constraint
* <code>context Class1
* def: testSortedByIteratorExp01() : OrderedSet(Integer) =
OrderedSet{3, 2, 1}->sortedBy(i: Integer | i)</code></p>
*/
public java.util.List<Integer>
testpackage.Class1.testSortedByIteratorExp01( ) {
java.util.ArrayList<Integer> collection1;
collection1 = new java.util.ArrayList<Integer>();
collection1.add(new Integer(3));
collection1.add(new Integer(2));
collection1.add(new Integer(1));
java.util.ArrayList<Integer> result1;
java.util.Comparator<Integer> comparator1;
result1 = collection1;
comparator1 = new java.util.Comparator<Integer>() {
/** Method which compares two elements of the collection. */
public int compare(Integer anElement1, Integer anElement2) {
int result2;
result2 = 0;
if (anElement1 < anElement2) {
result2 = -1;
} else if (anElement1 > anElement2) {
result2 = 1;
}
return result2;
}
};
java.util.Collections.sort(result1, comparator1);
return result1;
}
}
Althoug AJDT parses and compiles the code correctly, the initialization
of the anonymous classes causes a runtime exception:
java.lang.IllegalAccessError: tried to access class testpackage.Class1$1
from class
testpackage.constraints.Class1_DefAspect_testSortedByIteratorExp01
at
testpackage.constraints.Class1_DefAspect_testSortedByIteratorExp01.ajc$interMethod$testpackage_constraints_Class1_DefAspect_testSortedByIteratorExp01$testpackage_Class1$testSortedByIteratorExp01(Class1_DefAspect_testSortedByIteratorExp01.aj:28)
at testpackage.Class1.testSortedByIteratorExp01(Class1.java:1)
at
testpackage.constraints.Class1_DefAspect_testSortedByIteratorExp01.ajc$interMethodDispatch1$testpackage_constraints_Class1_DefAspect_testSortedByIteratorExp01$testpackage_Class1$testSortedByIteratorExp01(Class1_DefAspect_testSortedByIteratorExp01.aj)
...
My questions are:
- Are anonyomous classes allowed within AspectJ aspects at all?
- Is there any way to get a workaround for such a problem?
Cheers and thanks,
Claas Wilke