Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] NoSuchMethod Exception with aspected Code !

> I would like to know what
> difference it made using aspectpath.

There is no guarantee stated in the documentation that
compiling the same aspect twice will result in the
same advice "signatures" in the aspect .class file.
Your building repeatedly from the same source file
produced differences that made the difference.

Arguably, this is a bug in the docs and the
implementation.  There are many people who would
prefer advice be named for many reasons, and this
might be another one.  But to date we have not
required AspectJ implementations to associate advice
with identifiers or signatures that remain constant
across different versions of the class if the
declaration changes.  I suspect we will revisit
this when backwards binary compatibility becomes
important.

Wes

ravi varanasi wrote:

Wes,
    Thanks for the suggestion. I have compiled using aspectpath and it
worked. IT was not a classpath problem, for sure. I would like to know what
difference it made using aspectpath.

Thanks again,

Ravi Varanasi


----- Original Message -----
From: "Wes Isberg" <wes@xxxxxxxxxxxxxx>
To: <aspectj-users@xxxxxxxxxxx>
Sent: Sunday, October 19, 2003 8:41 PM
Subject: Re: [aspectj-users] NoSuchMethod Exception with aspected Code !



Given the different bytecode names for the advice, perhaps
make sure the aspect class is the one produced when you weave
the input jars.  If you reuse the aspect, a better way to
build would be to compile the aspect first, and then put it
on the aspectpath when compiling each client, and on the
runtime classpath.

Otherwise, perhaps the NoSuchMethodError was caused by failing
to load the aspect.  Try setting up the classpath as usual, but
just running some code[1] that refers to the aspect directly
and has no aspects associated with it, e.g.,

  ... {some method}.. {
      System.out.println("aspect class: " + Test.class.getName());
  }

If that fails, it's a classpath problem (the aspect or
the aspectj runtime classes are not visible from the classloader
that loaded the target class).

Wes

[1] Best to compile this with javac, with aspect on the classpath.

ravi varanasi wrote:


Hi All,
   I have encounter a weird problem while aspecting a jar file.

Following is the background to the problem :-

Name of my aspect is: Test.java.
Command to weave the input jar with the aspect: ajc -injars

input.jar -outjar out.jar Test.java

One of the classes which met the criteria for JoinPoint has been

modified by the ajc and written to the out.jar. Following is the piece of
code from the aspect weaved class (generated using a decompiler) :-

   public Object getAttribute(String arg0)
   {
       Test.aspectOf().ajc$before$first_aspect_Test$5aa(ajc$tjp_0);
       HTTPLogger.logUnableToDeserializeNamedAttribute(getLogContext(),

arg0, runtimeexception);

       attributes.remove(arg0);
       return null;
       Exception exception;
       exception;


Test.aspectOf().ajc$afterThrowing$first_aspect_Test$3d5(exception);

       throw exception;
   }

Please note the calls

Test.aspectOf().ajc$before$first_aspect_Test$5aa(ajc$tjp_0); and
Test.aspectOf().ajc$afterThrowing$first_aspect_Test$3d5(exception); inserted
by the ajc in the original method getAttribute(String). These methods
ajc$before$first_aspect_Test$5aa(ajc$tjp_0); &
ajc$afterThrowing$first_aspect_Test$3d5(exception); are not there in the
Test.class.

Following is the method signature map of my aspect Test.java (generated

using javap):

public class first.aspect.Test extends java.lang.Object {
   public static java.lang.String methodName;
   public static final first.aspect.Test ajc$perSingletonInstance;
   static {};
   public void setMethodName(java.lang.String);
   public java.lang.String getMethodName();
   public first.aspect.Test();
   public void

ajc$before$first_aspect_Test$3d5(org.aspectj.lang.JoinPoint$Stat

icPart);
   public static first.aspect.Test aspectOf();
   public static boolean hasAspect();
}


My program fails with java.lang.NoSuchMethodError:

first.aspect.Test.ajc$before$first_aspect_Test$5aa(Lorg/aspectj/lang/JoinPoi
nt$StaticPart;)V exception when I try to execute.

Any suggestions, why this is happening? Is this a bug or I am doing

something wrong???

Following is the Test.java source:

package first.aspect;

public aspect Test {

 public Test() {
   System.out.println("Constructor: Test");
 }

 pointcut callWLServlet() : execution ( * weblogic.servlet..*.*(..) );
 pointcut callServlet() : execution ( * javax.servlet..*.*(..) );

 pointcut excludeInternal() : execution ( *

weblogic.management.internal..*.*(..) );

 pointcut excludeTools() : execution ( *

weblogic.management.tools..*.*(..) );

 pointcut excludeInfo() : execution ( *

weblogic.management.info..*.*(..) );

 after() throwing (Exception npe) :(
        callServlet() &&
        callWLServlet() &&
       (!excludeInternal()) &&
       (!excludeTools()) &&
       (!excludeInfo())
       ) {
         System.out.println("Logging exception using Aspect: ");
         System.out.println("=============================== ");
         System.out.println("Message: " + npe.getMessage() );
         System.out.println("=============================== ");
 }

 before() : ( callServlet() &&
              callWLServlet() &&
              ( ! excludeInternal() ) &&
              ( ! excludeTools() ) &&
              ( ! excludeInfo() )
            ) {

     if ( methodName.equals( thisJoinPoint.getSignature().getName() ) )

{

       System.out.println("---------> Matched call: " + methodName );
       throw new NullPointerException("Aspected Exception");
     } else {
       //System.out.println("========> Method call: " +

thisJoinPoint.getSignature().getName() + " <=========");

     }
 }
}
Thanks,

Ravi Varanasi

408 394 3273



_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users




Back to the top