diff options
author | Mark Wielaard <mark@klomp.org> | 2005-07-15 12:53:14 +0000 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2005-07-15 12:53:14 +0000 |
commit | ee8622b2db7af1eb939e358dd599cca3adca0777 (patch) | |
tree | ea68cfd8747a902ae4e1dd61878788de2e734f0f | |
parent | caaedaabb5f445a1826d804543ffefc68ef566c5 (diff) | |
download | classpath-ee8622b2db7af1eb939e358dd599cca3adca0777.tar.gz |
2005-07-15 Mark Wielaard <mark@klomp.org>
* java/util/logging/Logger.java (getCallerStackFrame):
Make sure index < stackTrace.length and return null otherwise.
(log): Check for caller == null.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | java/util/logging/Logger.java | 30 |
2 files changed, 24 insertions, 12 deletions
@@ -1,3 +1,9 @@ +2005-07-15 Mark Wielaard <mark@klomp.org> + + * java/util/logging/Logger.java (getCallerStackFrame): + Make sure index < stackTrace.length and return null otherwise. + (log): Check for caller == null. + 2005-07-15 Roman Kennke <roman@kennke.org> * javax/swing/AbstractButton.java diff --git a/java/util/logging/Logger.java b/java/util/logging/Logger.java index 264ae1fa5..ae985a93c 100644 --- a/java/util/logging/Logger.java +++ b/java/util/logging/Logger.java @@ -585,10 +585,10 @@ public class Logger String message, Object param) { - StackTraceElement caller = getCallerStackFrame(); + StackTraceElement caller = getCallerStackFrame(); logp(level, - caller.getClassName(), - caller.getMethodName(), + caller != null ? caller.getClassName() : "<unknown>", + caller != null ? caller.getMethodName() : "<unknown>", message, param); } @@ -600,8 +600,8 @@ public class Logger { StackTraceElement caller = getCallerStackFrame(); logp(level, - caller.getClassName(), - caller.getMethodName(), + caller != null ? caller.getClassName() : "<unknown>", + caller != null ? caller.getMethodName() : "<unknown>", message, params); } @@ -611,10 +611,10 @@ public class Logger String message, Throwable thrown) { - StackTraceElement caller = getCallerStackFrame(); + StackTraceElement caller = getCallerStackFrame(); logp(level, - caller.getClassName(), - caller.getMethodName(), + caller != null ? caller.getClassName() : "<unknown>", + caller != null ? caller.getMethodName() : "<unknown>", message, thrown); } @@ -1162,19 +1162,25 @@ public class Logger /** * Gets the StackTraceElement of the first class that is not this class. * That should be the initial caller of a logging method. - * @return caller of the initial looging method + * @return caller of the initial logging method or null if unknown. */ private StackTraceElement getCallerStackFrame() { Throwable t = new Throwable(); StackTraceElement[] stackTrace = t.getStackTrace(); int index = 0; + // skip to stackentries until this class - while(!stackTrace[index].getClassName().equals(getClass().getName())){index++;} + while(index < stackTrace.length + && !stackTrace[index].getClassName().equals(getClass().getName())) + index++; + // skip the stackentries of this class - while(stackTrace[index].getClassName().equals(getClass().getName())){index++;} + while(index < stackTrace.length + && stackTrace[index].getClassName().equals(getClass().getName())) + index++; - return stackTrace[index]; + return index < stackTrace.length ? stackTrace[index] : null; } /** |