From: jhugunin Date: Wed, 21 May 2003 17:51:24 +0000 (+0000) Subject: fix for Bugzilla Bug 37758 X-Git-Tag: V1_1_0~88 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=556537033f794d632baccf560a06414755b58381;p=aspectj.git fix for Bugzilla Bug 37758 Weaving rt.jar results in stack overflow --- diff --git a/weaver/src/org/aspectj/weaver/bcel/Utility.java b/weaver/src/org/aspectj/weaver/bcel/Utility.java index 9dc9e2a90..d2179010b 100644 --- a/weaver/src/org/aspectj/weaver/bcel/Utility.java +++ b/weaver/src/org/aspectj/weaver/bcel/Utility.java @@ -421,19 +421,42 @@ public class Utility { } /** returns -1 if no source line attribute */ + // this naive version overruns the JVM stack size, if only Java understood tail recursion... +// public static int getSourceLine(InstructionHandle ih) { +// if (ih == null) return -1; +// +// InstructionTargeter[] ts = ih.getTargeters(); +// if (ts != null) { +// for (int j = ts.length - 1; j >= 0; j--) { +// InstructionTargeter t = ts[j]; +// if (t instanceof LineNumberTag) { +// return ((LineNumberTag)t).getLineNumber(); +// } +// } +// } +// return getSourceLine(ih.getNext()); +// } + + public static int getSourceLine(InstructionHandle ih) { - if (ih == null) return -1; - - InstructionTargeter[] ts = ih.getTargeters(); - if (ts != null) { - for (int j = ts.length - 1; j >= 0; j--) { - InstructionTargeter t = ts[j]; - if (t instanceof LineNumberTag) { - return ((LineNumberTag)t).getLineNumber(); - } - } - } - return getSourceLine(ih.getNext()); + int lookahead=0; + // arbitrary rule that we will never lookahead more than 100 instructions for a line # + while (lookahead++ < 100) { + if (ih == null) return -1; + + InstructionTargeter[] ts = ih.getTargeters(); + if (ts != null) { + for (int j = ts.length - 1; j >= 0; j--) { + InstructionTargeter t = ts[j]; + if (t instanceof LineNumberTag) { + return ((LineNumberTag)t).getLineNumber(); + } + } + } + ih = ih.getNext(); + } + //System.err.println("no line information available for: " + ih); + return -1; } // assumes that there is no already extant source line tag. Otherwise we'll have to be better.