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.
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to