CatchClauseSignature has broken operationtags/v_preCompileLoopAlteration
@@ -7136,4 +7136,9 @@ | |||
<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> |
@@ -0,0 +1,42 @@ | |||
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"); | |||
} | |||
} |
@@ -190,8 +190,8 @@ public class Member implements Comparable { | |||
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, | |||
@@ -596,11 +596,9 @@ public class Member implements Comparable { | |||
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(); |
@@ -26,7 +26,7 @@ import org.aspectj.bridge.ISourceLocation; | |||
*/ | |||
public class ResolvedMember extends Member implements IHasPosition { | |||
protected String[] parameterNames = null; | |||
public String[] parameterNames = null; | |||
protected TypeX[] checkedExceptions = TypeX.NONE; | |||
@@ -40,6 +40,7 @@ import org.apache.bcel.generic.NEW; | |||
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; | |||
@@ -408,11 +409,16 @@ public class BcelShadow extends Shadow { | |||
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); | |||
@@ -424,6 +430,27 @@ public class BcelShadow extends Shadow { | |||
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 */ | |||