Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] aspects in annotations

Hi,

I am trying to use annotation to represent my aspects for handling the exception thrown from a method. But I get the following error while running using aj5. Can anyone help?

-------------------------------------------------------------------------------------------------
info register classloader sun.misc.Launcher$AppClassLoader@7494106
info using file:/home/eric/java/test/aop/J.jar!/META-INF/aop.xml
info register aspect Ap
error at Ap.java::0 the last parameter of this advice must be named 'ex' and be of a subtype of Throwable warning register definition failed -- (AbortException) the last parameter of this advice must be named 'ex' and be of a subtype of Throwable the last parameter of this advice must be named 'ex' and be of a subtype of Throwable Message: error at Ap.java::0 the last parameter of this advice must be named 'ex' and be of a subtype of Throwable org.aspectj.bridge.AbortException: the last parameter of this advice must be named 'ex' and be of a subtype of Throwable at org.aspectj.weaver.tools.WeavingAdaptor$WeavingAdaptorMessageHandler.handleMessage(WeavingAdaptor.java:413) at org.aspectj.weaver.bcel.AtAjAttributes.readAj5MethodAttributes(AtAjAttributes.java:401) at org.aspectj.weaver.bcel.BcelMethod.unpackAjAttributes(BcelMethod.java:109)
      at org.aspectj.weaver.bcel.BcelMethod.<init>(BcelMethod.java:73)
at org.aspectj.weaver.bcel.BcelObjectType.getDeclaredMethods(BcelObjectType.java:211) at org.aspectj.weaver.ReferenceType.getDeclaredMethods(ReferenceType.java:476) at org.aspectj.weaver.ResolvedType.getDeclaredAdvice(ResolvedType.java:699) at org.aspectj.weaver.ResolvedType.getDeclaredShadowMungers(ResolvedType.java:736) at org.aspectj.weaver.ResolvedType.collectShadowMungers(ResolvedType.java:572) at org.aspectj.weaver.ResolvedType.collectCrosscuttingMembers(ResolvedType.java:501) at org.aspectj.weaver.CrosscuttingMembersSet.addOrReplaceAspect(CrosscuttingMembersSet.java:61) at org.aspectj.weaver.bcel.BcelWeaver.addLibraryAspect(BcelWeaver.java:180) at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.registerAspects(ClassLoaderWeavingAdaptor.java:325) at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.registerDefinitions(ClassLoaderWeavingAdaptor.java:181) at org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor.initialize(ClassLoaderWeavingAdaptor.java:123) at org.aspectj.weaver.loadtime.Aj$ExplicitlyInitializedClassLoaderWeavingAdaptor.initialize(Aj.java:130) at org.aspectj.weaver.loadtime.Aj$ExplicitlyInitializedClassLoaderWeavingAdaptor.getWeavingAdaptor(Aj.java:135) at org.aspectj.weaver.loadtime.Aj$WeaverContainer.getWeaver(Aj.java:101)
      at org.aspectj.weaver.loadtime.Aj.preProcess(Aj.java:61)
at org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter.transform(ClassPreProcessorAgentAdapter.java:52) at sun.instrument.TransformerManager.transform(TransformerManager.java:122) at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:155)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

java.lang.IllegalArgumentException
      at A.stop(A.java:19)
      at A.main(A.java:30)

------------------------------------------------------------------------------------------------
Here is my aop.xml

<?xml version="1.0"?>

<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD 1.5.0//EN" "http://.../dtd/aspectj_1_5_0.dtd";>

<aspectj>

<weaver options="-1.5 -Xreweavable -verbose -showWeaveInfo">

<include within="*"/>

</weaver>

<aspects>

  <!-- declare existing aspects to the weaver -->
  <aspect name="Ap"/>

</aspects>

</aspectj>

------------------------------------------------------------------------------------------------
My java sources:

Ap.java

import org.aspectj.lang.annotation.*;

@Aspect ("issingleton()")
public class Ap
{
@AfterThrowing (pointcut = "(execution(public void A.start() throws java.lang.Exception) || execution(public void A.stop() throws java.lang.Exception))", throwing = "ex")
public void  handleException(Exception  ex) throws Exception
{
  if (ex instanceof IllegalArgumentException)
  {
    throw  new Exception(ex.getMessage());
  }
  else
  {
    throw  ex;
  }
}
}

A.java

public class A implements Ai
{
private  int  i = 0;

public void start() throws Exception
{
  i++;

  if (i == 0)
  {
    throw new IllegalArgumentException();
  }
}

public void stop() throws Exception
{
  if (i != 0)
  {
    throw new IllegalArgumentException();
  }
}

public static void main(String[] args)
{
  A  a = new A();

  try
  {
    a.start();
    a.stop();
  }
  catch (Exception e)
  {
    e.printStackTrace();
  }
}
}

Ai.java

public interface Ai
{
void start() throws Exception;
void stop() throws Exception;
}


Thanks,
Eric



Back to the top