Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] VerifyError on mockito woven class, despite pointcut ignoring it

That loadAllDetached method is a bit complicated if I look in the woven output you included. Pinpointing where the stack height is inconsistent would be time consuming. The amount of cflow related weaving also makes me feel that maybe we could improve the pointcut to weave less (but I'm not totally clear on your use case so maybe not):

 cflow(within(*..*EnhancerByMockito*))

will weave the counter code into every single join point in that Enhancer class. Every get/set/handler/etc - if you could get away with it you'd be better off with this:

cflow(within(*..*EnhancerByMockito*) && execution(* *(..)))

or maybe "cflow(execution(* *..*EnhancerByMockito*.*(..)))"

Which only weaves the method execution join points.

AspectJ weaving is built on patterns, the patterns typically produced by compilers. So if it needs to weave a particular instruction it recognizes it and the surrounding instructions and knows what to do. If 'something else' is generating the code, the pattern may be odd and cause problems in the weaving process. e.g. cglib here generating byte code - if cglib isn't quite producing what a compiler would produce to achieve the same thing, it can cause problems like this.

Andy



On 21 July 2014 15:39, Steve Ash <stevemash@xxxxxxxxx> wrote:
Ah that makes sense.  The cflow that was causing the problem was this:

@Pointcut("cflow(within(junit..*)) || cflow(within(*..*EnhancerByMockito*))")
  public void frameworkCode() {
  }

I had actually removed that (hence why the copy/pasted version in my first email missed this) but hadn't deployed that to my local maven repo so was running off of the version with the extra cflow.  Anyways removing that seems to have fixed it!  Thanks!

Any thought as to why the verify error is happening at all?  I actually had a few other failures from other tests that had mockito mocks woven accidentally -- and they failed with different verify errors.

Steve



On Mon, Jul 21, 2014 at 4:20 PM, Andy Clement <andrew.clement@xxxxxxxxx> wrote:
For some language constructs implicit weaving goes on. You wouldn't see a weave info message for this but the code is modified to support the pointcuts you are using. I suspected this when you described the problem and showed your aspect, then I looked in the woven code and it was what I expected.  The cflow pointcut inserts code so that we know if we are in a control flow. For example:

execution(* foo(..)) && cflow(execution(* bar(..))

will advise 'execution of foo' with a runtime check before the advice is called. That runtime check will be on a counter, which is incremented by code inserted into the execution of bar because of the cflow. So this:

public void foo() {
}

public void bar() {
  foo();
}

becomes:

public void foo() {
  if (counter>0) callAdvice();
}

public void bar() {
  try {
     counter++;
     foo();
  } finally {
     counter--;
  }
}

You are experiencing a variant of this. But at the moment I don't quite see which cflow is causing the proxy to be modified. You can probably experiment to determine it. do you just have the two or are there some others lurking?

cheers,
Andy



On 21 July 2014 09:42, Steve Ash <stevemash@xxxxxxxxx> wrote:
I am getting a VerifyError on a dynamically generated class which is a mock of one of my types.  I don't want to weave mockito generated classes.  I turned on weaver options -verbose and -showWeaveInfo and saw that the mockito generated classes were being woven.  So I added elements to the pointcut to skip these cglib/mockito generated classes.  Here is my aop.xml pointcut:

myTypes is: 
within(com.argodata..*) AND call(* *..*(..)) AND !within(*..*EnhancerBy*) AND !within(*..*CGLIB*)

When I added the !within for classes with "EnhancedBy" then (as expected) the classes generated by Mockito didn't show up anymore in the ShowWeaveInfo output.  So you would think its not weaving them... but it is!  If I turn on <dump> I get before and afters for the mockito class and the after has advice woven in!  I've attached the before and afters.

Here is my aspect:

@Pointcut("")
  public abstract void myTypes();

  @Pointcut("cflow(adviceexecution() && within(ExceptionAspect))")
  public void thisAdvice() {
  }

  @Pointcut("cflow(within(junit..*))")
  public void frameworkCode() {
  }

  @Pointcut("myTypes() && within(java.lang.Object+) && !handler(*)")
  public void eligibleTypes() {
  }

  @AfterThrowing(pointcut = "eligibleTypes() && !frameworkCode() && !thisAdvice()", throwing = "e")
  public void afterThrown(Exception e) {
    Bushwhacker.tryForDefault().handle(e);
  }

So I want all  calls within my code to go through this custom exception handling stuff.

The verify error I get is:

Caused by: java.lang.VerifyError: (class: com/argodata/fraud/commons/database/dao/AmlTranTypeDao$$EnhancerByMockitoWithCGLIB$$e76ea9ca, method: loadAllDetached signature: ()Ljava/lang/Iterable;) Inconsistent stack height 1 != 0
at sun.reflect.GeneratedSerializationConstructorAccessor5.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)

I have attached a zip (rename .piz to .zip) of the before and after woven class and the complete output of LTW with ShowWeaveInfo.

I'm at a loss here as to why its still weaving when my pointcut says no (and the ShowWeaveInfo seems to agree!).  The verifyError is obvously the real problem, I guess, but I don't really care about weaving mockito generated classes.  I'd prefer to just work around this by ignoring them.




_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top