Logging calls to external code with an aspect leads to exceptions

80 views Asked by At

I am trying to find list of all external functions that are being called in a program. Program under test is in package net.sf.gaeappmanager.google.appengine and external functions are in package and subpackage of org.apache.http...

To achieve this, I have written aspects as below:

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()
    );
}

But this aspect is not working as it should be. It is throwing unhandled exceptions. If I use only System.out.println("Function of http Package") without thisJoinPoint then it works fine.

Added Extra Information as required by @kriegaex

I am executing PUT using test cases generated through Evosuite tool. First I am including here the test case:

@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();
  }
}

When I am executing this test case (with the aspects given above), I am getting the following exceptions:

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

If I execute the same test case but without thisJoinPoint in the aspects, I get the following result:

.

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

My main concern is why adding thisJoinPoint in the aspects is resulting the exceptions and how I can get the list of all external functions in a program.

0

There are 0 answers