<run class="SubtypeConstructorCW"/>
</ajc-test>
+ <ajc-test dir="bugs" pr="50570"
+ title="CatchClauseSignature has broken operation">
+ <compile files="HandlerSig.java"/>
+ <run class="HandlerSig"/>
+ </ajc-test>
</suite>
--- /dev/null
+import org.aspectj.testing.Tester;
+
+import org.aspectj.lang.reflect.*;
+
+public class HandlerSig {
+
+ public void doSomething() {
+ // Get around "unreachable code error...
+ if (true)
+ {
+ throw new BusinessException("Surprise!!");
+ }
+ System.out.println("Busy doing something.");
+ }
+
+ public static void main(String[] args) {
+ try {
+ HandlerSig m = new HandlerSig();
+ m.doSomething();
+ } catch (BusinessException be) {
+ Tester.checkEqual(be.getMessage(), "Surprise!!");
+ }
+ }
+}
+
+class BusinessException extends RuntimeException {
+ BusinessException(String message) {
+ super(message);
+ }
+}
+
+aspect AppMonitor {
+ pointcut problemHandling() : handler(Throwable+);
+
+ before() : problemHandling() {
+ CatchClauseSignature cSig =
+ (CatchClauseSignature) thisJoinPointStaticPart.getSignature();
+
+ Tester.checkEqual(cSig.getParameterType(), BusinessException.class);
+ Tester.checkEqual(cSig.getParameterName(), "be");
+ }
+}
paramTys);
}
- public static Member makeExceptionHandlerSignature(TypeX inType, TypeX catchType) {
- return new Member(
+ public static ResolvedMember makeExceptionHandlerSignature(TypeX inType, TypeX catchType) {
+ return new ResolvedMember(
HANDLER,
inType,
Modifier.STATIC,
buf.append('-');
buf.append(makeString(getParameterTypes()[0]));
buf.append('-');
- //XXX we don't actually try to find the handler parameter name
- //XXX it probably wouldn't be too hard
String pName = "<missing>";
- //String[] pNames = getParameterNames(world);
- //if (pNames != null) pName = pNames[0];
+ String[] names = getParameterNames(world);
+ if (names != null) pName = names[0];
buf.append(pName);
buf.append('-');
return buf.toString();
*/
public class ResolvedMember extends Member implements IHasPosition {
- protected String[] parameterNames = null;
+ public String[] parameterNames = null;
protected TypeX[] checkedExceptions = TypeX.NONE;
import org.apache.bcel.generic.ObjectType;
import org.apache.bcel.generic.ReturnInstruction;
import org.apache.bcel.generic.SWAP;
+import org.apache.bcel.generic.StoreInstruction;
import org.apache.bcel.generic.TargetLostException;
import org.apache.bcel.generic.Type;
import org.aspectj.bridge.ISourceLocation;
InstructionList body = enclosingMethod.getBody();
TypeX catchType = exceptionRange.getCatchType();
TypeX inType = enclosingMethod.getEnclosingClass().getType();
+
+ ResolvedMember sig = Member.makeExceptionHandlerSignature(inType, catchType);
+
+
+ sig.parameterNames = new String[] {findHandlerParamName(startOfHandler)};
BcelShadow s =
new BcelShadow(
world,
ExceptionHandler,
- Member.makeExceptionHandlerSignature(inType, catchType),
+ sig,
enclosingMethod,
enclosingShadow);
ShadowRange r = new ShadowRange(body);
exceptionRange.updateTarget(startOfHandler, start, body);
return s;
}
+
+ private static String findHandlerParamName(InstructionHandle startOfHandler) {
+ if (startOfHandler.getInstruction() instanceof StoreInstruction &&
+ startOfHandler.getNext() != null)
+ {
+ int slot = ((StoreInstruction)startOfHandler.getInstruction()).getIndex();
+ //System.out.println("got store: " + startOfHandler.getInstruction() + ", " + index);
+ InstructionTargeter[] targeters = startOfHandler.getNext().getTargeters();
+ for (int i=targeters.length-1; i >= 0; i--) {
+ if (targeters[i] instanceof LocalVariableTag) {
+ LocalVariableTag t = (LocalVariableTag)targeters[i];
+ if (t.getSlot() == slot) {
+ return t.getName();
+ }
+ //System.out.println("tag: " + targeters[i]);
+ }
+ }
+ }
+
+ return "<missing>";
+ }
/** create an init join point associated w/ an interface in the body of a constructor */