Browse Source

Fix for Bugzilla Bug 49638 exception logging: after() throwing advice can't convert Throwable obj to string and ajc aborts

tags/mostlyLastEclipse2xTree_20040112
jhugunin 20 years ago
parent
commit
7b081f2e0b

+ 6
- 1
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/parser/AjParser.java View File

} else if (CharOperation.equals(name, "returning".toCharArray())) { } else if (CharOperation.equals(name, "returning".toCharArray())) {
adviceDecl.kind = AdviceKind.AfterReturning; adviceDecl.kind = AdviceKind.AfterReturning;
} else { } else {
//XXX illegal name here
problemReporter().parseError(
start,
end,
name,
String.valueOf(name),
new String[] {"throwing", "returning", ":"});
} }
} }



+ 12
- 1
tests/ajcTests.xml View File

</message> </message>
</compile> </compile>
</ajc-test> </ajc-test>

<ajc-test dir="bugs"
title="Appropriate message for 'after() thowing(Throwable th)' syntax error"
pr="49638"
>
<compile
files="AfterThrowingAdviceSyntaxError.java" >
<message kind="error" line="21" />
<message kind="error" line="23" />
</compile>
</ajc-test>
</suite> </suite>

+ 28
- 0
tests/bugs/AfterThrowingAdviceSyntaxError.java View File

import org.aspectj.lang.*;

public class AfterThrowingAdviceSyntaxError {

public static void main(String[] args) {
perform();
}

private static void perform() {
Object nullObj = null;
nullObj.toString();
}
}

aspect ExceptionLoggerAspectV2
{

pointcut exceptionLogMethods()
: call(* *.*(..)) && !within(ExceptionLoggerAspectV2);

after() thowing(Throwable ex) : exceptionLogMethods() {
Signature sig = thisJoinPointStaticPart.getSignature();
System.out.printl("WARNING: "
+ sig.getDeclaringType().getName() + " "
+ sig.getName() + " "
+ "Exception logger aspect " + ex);
}
}

Loading…
Cancel
Save