[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[aspectj-users] [BUG?] java.lang.VerifyError with @AspectJ annotation (but with a certain call to print, it works!?)
|
- From: João Gonçalves <jocolimonada@xxxxxxxxx>
- Date: Mon, 31 Aug 2009 08:45:24 +0100
- Delivered-to: aspectj-users@eclipse.org
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=PPXjU0dZ0+OCINwbZ7zgIc7ZieNJUFMd4He4NnVZgiA=; b=q3bzXPHABeqXjRhyz1Wq2RNEbv2juIh511e9GMhJuvWOYwWefv1hdHbysdqfIIlvdV R0q/+jDHVMKpCZHb8uTvFnrU26H1Kr8ZI2nYADy65Jorq7XA0y2mW795E1i0QuyRiqRY yj0jXw/KhnK0K6OhfRzGg76xf1/+qvm/0t9Os=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=mi1w8q0ZaynM/J70u2bqPPLU6ryPd1z/0P9TL94EOb4SoukCZgiwI5ozwm240DEX0f LrdCv3C+k2EKZonbBsZfe2rSmC3Jgz7J1VR9E9ih8pRh0G97kZzeZGJDvkPo2yOoDd5U /uRgvYhMmKjuVAtQBFdHkP8YtRVDNkrqhy5HE=
Hi,
I'm using Eclipse 3.4.1, AspectJ 1.6.5 and AJDT 2.0.0.
I've created a very simple test scenario that utilizes @AspectJ. When running a main method in a class or when running a Junit test, I get the following error:
Exception in thread "main" java.lang.VerifyError: (class: figures/Line, method: move_aroundBody3$advice signature: (Lfigures/Line;Lfigures/Point;IILorg/aspectj/lang/JoinPoint;Lanswers/Answer2h;Lorg/aspectj/lang/ProceedingJoinPoint;Lfigures/FigureElement;II)V) Incompatible argument to function
at MainTest.main(MainTest.java:24)
Here's the aspect that is causing the error
===============================================================
Answer2h.java
===============================================================
package answers;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import figures.*;
import java.awt.Rectangle;
@Aspect
public class Answer2h {
@Pointcut("call(public void figures.FigureElement+.move(int, int))"
+"&& target(fe) && args(dx, dy)")
void movingFigureElement(FigureElement fe, int dx, int dy) {}
@Around("movingFigureElement(fe, dx, dy)")
public void checkIfBoundsMovedSame(ProceedingJoinPoint thisJoinPoint,
FigureElement fe, int dx, int dy) throws Throwable {
Rectangle rectangleBefore = new Rectangle(fe.getBounds());
thisJoinPoint.proceed(new Object[]{fe, dx, dy});
rectangleBefore.translate(dx, dy);
if(!rectangleBefore.equals(fe.getBounds()))
throw new IllegalStateException("move() invariant violation");
}
}
===============================================================
However, strangely, when I had the following 3 lines to my aspect (I was just doing debug), everything works normally:
===============================================================
Answer2h.java (with 3 more lines)
===============================================================
package answers;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import figures.*;
import java.awt.Rectangle;
@Aspect
public class Answer2h {
@Pointcut("call(public void figures.FigureElement+.move(int, int))"
+"&& target(fe) && args(dx, dy)")
void movingFigureElement(FigureElement fe, int dx, int dy) {}
@Around("movingFigureElement(fe, dx, dy)")
public void checkIfBoundsMovedSame(ProceedingJoinPoint thisJoinPoint,
FigureElement fe, int dx, int dy) throws Throwable {
Rectangle rectangleBefore = new Rectangle(fe.getBounds());
for(Object o: thisJoinPoint.getArgs()) {
System.out.print(o+" ");
}
thisJoinPoint.proceed(new Object[]{fe, dx, dy});
rectangleBefore.translate(dx, dy);
if(!rectangleBefore.equals(fe.getBounds()))
throw new IllegalStateException("move() invariant violation");
}
}
===============================================================
????
If I use any other print (and comment the privous print), the code continues giving the same error...
Examples (that don't work):
// System.out.println("ENTERED");
// System.out.println("Kind: "+thisJoinPoint.getKind());
// System.out.println("Signature: "+thisJoinPoint.getSignature());
// System.out.println("This: "+thisJoinPoint.getThis());
// System.out.println("Target: "+thisJoinPoint.getTarget());
Another interesting thing (that makes me believe it's some kind of bug). The Answer2h.java is equivalent to this one:
===============================================================
Answer2h.aj
===============================================================
package answers;
import figures.*;
import java.awt.Rectangle;
public aspect Answer2h {
pointcut movingFigureElement(FigureElement figureElement, int dx, int dy):
call(public void figures.FigureElement+.move(int, int)) &&
target(figureElement) &&
args(dx, dy);
void around(FigureElement figureElement, int dx, int dy):
movingFigureElement(figureElement, dx, dy) {
Rectangle rectangleBefore =
new Rectangle(figureElement.getBounds());
proceed(figureElement, dx, dy);
rectangleBefore.translate(dx, dy);
if(!rectangleBefore.equals(figureElement.getBounds()))
throw new IllegalStateException("move() invariant violation"); }
}
===============================================================
But this latter works!!
Can anyone tell me how to fix this?
Thanks.
Here's the MainTest.java code (not sure if it helps):
===============================================================
MainTest.java
===============================================================
import figures.Box;
import figures.FigureElement;
import figures.Group;
import figures.Line;
import figures.Point;
import figures.SlothfulPoint;
public class MainTest {
/**
* @param args
*/
public static void main(String[] args) {
Box bb;
Point p1;
Point p2;
Line l1;
SlothfulPoint sloth1;
Group g;
p1 = new Point(10, 100);
p2 = new Point(20, 200);
l1 = new Line(p1, p2); // line of the error
bb = new Box(5, 5, 10, 10);
sloth1 = new SlothfulPoint(0, 0);
g = new Group(p1);
FigureElement fe = new SlothfulPoint(10, 10);
try {
fe.move(10, 10);
System.out.println("should have thrown IllegalStateException");
} catch (IllegalStateException e) { e.printStackTrace(); }
p1.move(30, 45);
p2.move(10, 33);
}
}
===============================================================
P.S.:
When I use the MainTest.java to lauch the example, inside Answer2h.java I have to use this call to proceed:
thisJoinPoint.proceed(new Object[]{fe, dx, dy});
But, when I use the JUnit, the test oly runs if I use :
thisJoinPoint.proceed(new Object[]{fe, fe, dx, dy});
Why? Shouldn't the call be the same? And shouldn't the latter be the correct one ({target + 3 parameters})?
Regards.