info AspectJ Weaver Version DEVELOPMENT
built on
info register classloader
org.aspectj.weaver.loadtime.WeavingURLClassLoader
info using /C:/temp/ajcSandbox/ajcTest26696.tmp/META-INF/aop.xml
info register aspect Ap
info weaving 'A'
info weaver operating in
reweavable mode. Need to verify any required types exist.
weaveinfo Join point 'method-execution(void
A.start())' in Type 'A' (A.java:5)
advised by afterThrowing advice from 'Ap' (Ap.java)
weaveinfo Join point 'method-execution(void
A.stop())' in Type 'A' (A.java:15)
advised by afterThrowing advice from 'Ap' (Ap.java)
info weaving 'Ai'
info weaver operating in
reweavable mode. Need to verify any required types exist.
info weaving 'Ap'
info weaver operating in
reweavable mode. Need to verify any required types exist.
java.lang.Exception
at Ap.handleException(Ap.java:11)
at A.stop(A.java:21)
at A.main(A.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.aspectj.tools.ajc.AjcTestCase.run(AjcTestCase.java:609)
at org.aspectj.testing.RunSpec.execute(RunSpec.java:56)
at org.aspectj.testing.AjcTest.runTest(AjcTest.java:68)
at org.aspectj.testing.XMLBasedAjcTestCase.runTest(XMLBasedAjcTestCase.java:111)
at org.aspectj.systemtest.ajc150.Ajc150Tests.testError(Ajc150Tests.java:877)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester, SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/
Please respond to aspectj-users@xxxxxxxxxxx
Sent by:
aspectj-users-bounces@xxxxxxxxxxx
To:
aspectj-users@xxxxxxxxxxx
cc:
Subject:
[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
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users