使用方面记录对外部代码的调用会导致异常

时间:2016-07-03 09:28:42

标签: aop aspectj aspects

我正在尝试查找程序中正在调用的所有外部函数的列表。测试中的程序位于包net.sf.gaeappmanager.google.appengine中,外部函数位于org.apache.http..的包和子包中。

为实现这一目标,我写了以下几个方面:

public pointcut capturehttp() :
    within(net.sf.gaeappmanager..*) && 
    !within(gaeAspect) &&
    (
        call(* org.apache.http..*+.*(..)) ||
        call(org.apache.http..*+.new(..))
    );

after() : capturehttp() {
    System.out.println(
        "Function of http Package" +
        thisJoinPoint.getSignature().getName()
    );
}

但是这方面的工作不应该如此。它抛出了未经处理的异常。如果我只使用System.out.println("Function of http Package")而不使用thisJoinPoint,那么它可以正常工作。

根据@kriegaex

的要求添加了额外信息

我正在使用Evosuite工具生成的测试用例执行PUT。首先,我在这里包括测试用例:

@Test
  public void test0()  throws Throwable  {
      // Undeclared exception!
      try { 
        Manager.retrieveAppQuotaDetails("@;[", ")C)!L{Fy,b%<$%", "@;[", ")C)!L{Fy,b%<$%");
        fail("Expecting exception: NoClassDefFoundError");

      } catch(NoClassDefFoundError e) {
         //
         // org/apache/commons/logging/LogFactory
         //
         assertThrownBy("org.apache.http.impl.client.AbstractHttpClient", e);
      }
  }

  //Test case number: 1
  /*
   * 1 covered goal:
   * Goal 1. net.sf.gaeappmanager.google.appengine.Manager.<init>()V: root-Branch
   */

  @Test
  public void test1()  throws Throwable  {
      Manager manager0 = new Manager();
  }
}

当我执行此测试用例(具有上面给出的方面)时,我得到以下例外:

There were 2 failures:
1) test1(net.sf.gaeappmanager.google.appengine.Manager_ESTest)
java.lang.NoClassDefFoundError: Could not initialize class net.sf.gaeappmanager.
google.appengine.Manager
        at net.sf.gaeappmanager.google.appengine.Manager_ESTest.test1(Manager_ES
Test.java:48)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framework
Method.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCal
lable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMe
thod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMet
hod.java:17)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.
java:26)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.ja
va:27)
        at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement
.call(FailOnTimeout.java:298)
        at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement
.call(FailOnTimeout.java:292)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.lang.Thread.run(Thread.java:745)
2) test0(net.sf.gaeappmanager.google.appengine.Manager_ESTest)
java.lang.AssertionError: Exception was not thrown in org.apache.http.impl.clien
t.AbstractHttpClient
        at org.evosuite.runtime.EvoAssertions.assertThrownBy(EvoAssertions.java:
70)
        at net.sf.gaeappmanager.google.appengine.Manager_ESTest.test0(Manager_ES
Test.java:36)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(Framework
Method.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCal
lable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMe
thod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMet
hod.java:17)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.
java:26)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.ja
va:27)
        at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement
.call(FailOnTimeout.java:298)
        at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement
.call(FailOnTimeout.java:292)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.lang.Thread.run(Thread.java:745)

FAILURES!!!
Tests run: 2,  Failures: 2

如果我在方面执行相同的测试用例但没有 thisJoinPoint ,我会得到以下结果:

.Function of http Package
Time: 0.669
OK (2 tests)

我主要担心的是为什么在方面中添加 thisJoinPoint 会导致异常,以及如何获取程序中所有外部函数的列表。

0 个答案:

没有答案