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

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


Back to the top