From 7fbdd52e8f5a4a24aa56468612a718b2ada7bf6f Mon Sep 17 00:00:00 2001 From: wisberg Date: Sat, 19 Apr 2003 07:16:57 +0000 Subject: [PATCH] prevent div/0, NPE (by inspection) --- runtime/src/org/aspectj/runtime/internal/CFlowStack.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/src/org/aspectj/runtime/internal/CFlowStack.java b/runtime/src/org/aspectj/runtime/internal/CFlowStack.java index d6a4541a4..067860ce7 100644 --- a/runtime/src/org/aspectj/runtime/internal/CFlowStack.java +++ b/runtime/src/org/aspectj/runtime/internal/CFlowStack.java @@ -39,7 +39,8 @@ public class CFlowStack { } change_count++; // Collect more often if there are many threads, but not *too* often - if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/stacks.size())) { + int size = Math.max(1, stacks.size()); // should be >1 b/c always live threads, but... + if (change_count > Math.max(MIN_COLLECT_AT, COLLECT_AT/size)) { Stack dead_stacks = new Stack(); for (Enumeration e = stacks.keys(); e.hasMoreElements(); ) { Thread t = (Thread)e.nextElement(); @@ -79,7 +80,8 @@ public class CFlowStack { } public Object get(int index) { - return peekCFlow().get(index); + CFlow cf = peekCFlow(); + return (null == cf ? null : cf.get(index)); } public Object peekInstance() { -- 2.39.5