From fcedbe90d79f39dea9bee7d687d29edc67b032a5 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 13 Aug 2008 17:35:37 +0000 Subject: [PATCH] Thread.dumpStack() circumvents whatever logging is configured and writes directly to stderr. Logging an exception with the associated warning does the right thing and logs the stack trace via the logging system. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5318 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../admin/client/PulldownFieldEditor.java | 3 +-- .../crowd/chat/server/SpeakUtil.java | 3 +-- .../com/threerings/io/ObjectInputStream.java | 8 +++--- src/java/com/threerings/io/Streamer.java | 5 ++-- .../com/threerings/presents/dobj/DObject.java | 18 ++++++------- .../com/threerings/presents/dobj/DSet.java | 16 ++++++------ .../presents/server/ClientManager.java | 11 ++++---- .../presents/server/InvocationManager.java | 6 ++--- .../presents/server/InvocationSender.java | 13 ++++------ .../presents/server/PresentsClient.java | 4 +-- .../presents/server/PresentsDObjectMgr.java | 5 ++-- .../presents/server/net/Connection.java | 6 ++--- .../server/net/ConnectionManager.java | 8 +++--- .../presents/util/SafeSubscriber.java | 15 ++++------- .../com/threerings/util/MessageBundle.java | 9 +++---- src/java/com/threerings/util/TimeUtil.java | 25 ++++++++----------- 16 files changed, 60 insertions(+), 95 deletions(-) diff --git a/src/java/com/threerings/admin/client/PulldownFieldEditor.java b/src/java/com/threerings/admin/client/PulldownFieldEditor.java index 558b3e362..1efd44b69 100644 --- a/src/java/com/threerings/admin/client/PulldownFieldEditor.java +++ b/src/java/com/threerings/admin/client/PulldownFieldEditor.java @@ -132,8 +132,7 @@ public class PulldownFieldEditor extends FieldEditor } // cause shit to blow up minorly - log.warning("Value in dobj is not settable, disabling choice."); - Thread.dumpStack(); + log.warning("Value in dobj is not settable, disabling choice.", new Exception()); _value.setEnabled(false); } diff --git a/src/java/com/threerings/crowd/chat/server/SpeakUtil.java b/src/java/com/threerings/crowd/chat/server/SpeakUtil.java index a20a3cd0e..c5843e03e 100644 --- a/src/java/com/threerings/crowd/chat/server/SpeakUtil.java +++ b/src/java/com/threerings/crowd/chat/server/SpeakUtil.java @@ -175,8 +175,7 @@ public class SpeakUtil public static void sendMessage (DObject speakObj, ChatMessage msg) { if (speakObj == null) { - log.warning("Dropping speak message, no speak obj '" + msg + "'."); - Thread.dumpStack(); + log.warning("Dropping speak message, no speak obj '" + msg + "'.", new Exception()); return; } diff --git a/src/java/com/threerings/io/ObjectInputStream.java b/src/java/com/threerings/io/ObjectInputStream.java index 3666f07d9..2eee63536 100644 --- a/src/java/com/threerings/io/ObjectInputStream.java +++ b/src/java/com/threerings/io/ObjectInputStream.java @@ -122,11 +122,9 @@ public class ObjectInputStream extends DataInputStream // sanity check if (cmap == null) { // this will help with debugging - log.warning("Internal stream error, no class metadata [code=" + code + - ", ois=" + this + "]."); - Thread.dumpStack(); - log.warning( - "ObjectInputStream mappings " + StringUtil.toString(_classmap) + "."); + log.warning("Internal stream error, no class metadata", "code", code, + "ois", this, new Exception()); + log.warning("ObjectInputStream mappings", "map", _classmap); String errmsg = "Read object code for which we have no registered class " + "metadata [code=" + code + "]"; throw new RuntimeException(errmsg); diff --git a/src/java/com/threerings/io/Streamer.java b/src/java/com/threerings/io/Streamer.java index fce8788a1..c6e151ccc 100644 --- a/src/java/com/threerings/io/Streamer.java +++ b/src/java/com/threerings/io/Streamer.java @@ -113,9 +113,8 @@ public class Streamer if (stream == null) { // make sure this is a streamable class if (!isStreamable(target)) { - Thread.dumpStack(); - throw new IOException("Requested to stream invalid class '" + - target.getName() + "'"); + throw new IOException( + "Requested to stream invalid class '" + target.getName() + "'"); } // create a streamer for this class and cache it diff --git a/src/java/com/threerings/presents/dobj/DObject.java b/src/java/com/threerings/presents/dobj/DObject.java index fce4b4132..8a63bd59a 100644 --- a/src/java/com/threerings/presents/dobj/DObject.java +++ b/src/java/com/threerings/presents/dobj/DObject.java @@ -164,8 +164,7 @@ public class DObject } else { log.warning("Refusing subscriber that's already in the list", "dobj", which(), - "subscriber", sub); - Thread.dumpStack(); + "subscriber", sub, new Exception()); } } @@ -225,8 +224,7 @@ public class DObject _listeners = els; } else { log.warning("Refusing repeat listener registration [dobj=" + which() + - ", list=" + listener + "]"); - Thread.dumpStack(); + ", list=" + listener + "]", new Exception()); } } @@ -802,10 +800,7 @@ public class DObject // if we're on the authoritative server, we update the set immediately boolean alreadyApplied = false; if (_omgr != null && _omgr.isManager(this)) { - if (!set.add(entry)) { - // DSet will have logged a warning - Thread.dumpStack(); - } + set.add(entry); alreadyApplied = true; } // dispatch an entry added event @@ -823,8 +818,8 @@ public class DObject if (_omgr != null && _omgr.isManager(this)) { oldEntry = set.removeKey(key); if (oldEntry == null) { - log.warning("Requested to remove non-element", "set", name, "key", key); - Thread.dumpStack(); + log.warning("Requested to remove non-element", "set", name, "key", key, + new Exception()); } } // dispatch an entry removed event @@ -850,7 +845,8 @@ public class DObject if (_omgr != null && _omgr.isManager(this)) { oldEntry = set.update(entry); if (oldEntry == null) { - Thread.dumpStack(); + log.warning("Set update had no old entry", "name", name, "entry", entry, + new Exception()); } } // dispatch an entry updated event diff --git a/src/java/com/threerings/presents/dobj/DSet.java b/src/java/com/threerings/presents/dobj/DSet.java index 79ec74493..9cb480932 100644 --- a/src/java/com/threerings/presents/dobj/DSet.java +++ b/src/java/com/threerings/presents/dobj/DSet.java @@ -210,8 +210,7 @@ public class DSet { // the crazy sanity checks if (_size < 0 || _size > _entries.length || (_size > 0 && _entries[_size-1] == null)) { - log.warning("DSet in a bad way", "size", _size, "entries", _entries); - Thread.dumpStack(); + log.warning("DSet in a bad way", "size", _size, "entries", _entries, new Exception()); } return new Iterator() { @@ -232,8 +231,7 @@ public class DSet } if (_ssize != _size) { log.warning("Size changed during iteration", "ssize", _ssize, "nsize", _size, - "entries", _entries); - Thread.dumpStack(); + "entries", _entries, new Exception()); } } protected int _index = 0; @@ -282,7 +280,8 @@ public class DSet // if the element is already in the set, bail now if (eidx >= 0) { - log.warning("Refusing to add duplicate entry [entry=" + elem + ", set=" + this + "]."); + log.warning("Refusing to add duplicate entry", "entry", elem, "set", this, + new Exception()); return false; } @@ -294,8 +293,8 @@ public class DSet if (_size >= elength) { // sanity check if (elength > 2048) { - log.warning("Requested to expand to questionably large size [l=" + elength + "]."); - Thread.dumpStack(); + log.warning("Requested to expand to questionably large size", "l", elength, + new Exception()); } // create a new array and copy our data into it @@ -340,8 +339,7 @@ public class DSet { // don't fail, but generate a warning if we're passed a null key if (key == null) { - log.warning("Requested to remove null key."); - Thread.dumpStack(); + log.warning("Requested to remove null key.", new Exception()); return null; } diff --git a/src/java/com/threerings/presents/server/ClientManager.java b/src/java/com/threerings/presents/server/ClientManager.java index fb746cfcd..9aca1bccf 100644 --- a/src/java/com/threerings/presents/server/ClientManager.java +++ b/src/java/com/threerings/presents/server/ClientManager.java @@ -306,8 +306,8 @@ public class ClientManager { ClientObject clobj = _objmap.get(username); if (clobj == null) { - log.warning("Requested to release unmapped client object [username=" + username + "]."); - Thread.dumpStack(); + log.warning("Requested to release unmapped client object", "username", username, + new Exception()); return; } @@ -334,8 +334,8 @@ public class ClientManager { ClientObject clobj = _objmap.remove(oldname); if (clobj == null) { - log.warning("Requested to rename unmapped client object [username=" + oldname + "]."); - Thread.dumpStack(); + log.warning("Requested to rename unmapped client object", "username", oldname, + new Exception()); return false; } _objmap.put(newname, clobj); @@ -409,8 +409,7 @@ public class ClientManager client.connectionFailed(fault); } else if (!(conn instanceof AuthingConnection)) { - log.info("Unmapped connection failed? [conn=" + conn + ", fault=" + fault + "]."); - Thread.dumpStack(); + log.info("Unmapped connection failed?", "conn", conn, "fault", fault, new Exception()); } } diff --git a/src/java/com/threerings/presents/server/InvocationManager.java b/src/java/com/threerings/presents/server/InvocationManager.java index 653955570..7d03cdab9 100644 --- a/src/java/com/threerings/presents/server/InvocationManager.java +++ b/src/java/com/threerings/presents/server/InvocationManager.java @@ -165,15 +165,13 @@ public class InvocationManager _omgr.requireEventThread(); // sanity check if (marsh == null) { - log.warning("Refusing to unregister null marshaller."); - Thread.dumpStack(); + log.warning("Refusing to unregister null marshaller.", new Exception()); return; } if (_dispatchers.remove(marsh.getInvocationCode()) == null) { log.warning("Requested to remove unregistered marshaller? " + - "[marsh=" + marsh + "]."); - Thread.dumpStack(); + "[marsh=" + marsh + "].", new Exception()); } } diff --git a/src/java/com/threerings/presents/server/InvocationSender.java b/src/java/com/threerings/presents/server/InvocationSender.java index 1b08ef4b5..ba0ea8c29 100644 --- a/src/java/com/threerings/presents/server/InvocationSender.java +++ b/src/java/com/threerings/presents/server/InvocationSender.java @@ -21,8 +21,6 @@ package com.threerings.presents.server; -import com.samskivert.util.StringUtil; - import com.threerings.presents.client.InvocationReceiver.Registration; import com.threerings.presents.data.ClientObject; import com.threerings.presents.dobj.InvocationNotificationEvent; @@ -57,14 +55,13 @@ public abstract class InvocationSender // specific client Registration rreg = target.receivers.get(receiverCode); if (rreg == null) { - log.warning("Unable to locate receiver for invocation service notification " + - "[clobj=" + target.who() + ", code=" + receiverCode + - ", methId=" + methodId + ", args=" + StringUtil.toString(args) + "]."); - Thread.dumpStack(); + log.warning("Unable to locate receiver for invocation service notification", + "clobj", target.who(), "code", receiverCode, "methId", methodId, + "args", args, new Exception()); } else { -// Log.info("Sending notification [target=" + target + ", code=" + receiverCode + -// ", methodId=" + methodId + ", args=" + StringUtil.toString(args) + "]."); +// log.info("Sending notification", "target", target, "code", receiverCode, +// "methodId", methodId, "args", args); // create and dispatch an invocation notification event target.postEvent( diff --git a/src/java/com/threerings/presents/server/PresentsClient.java b/src/java/com/threerings/presents/server/PresentsClient.java index 274f9d5d3..524114624 100644 --- a/src/java/com/threerings/presents/server/PresentsClient.java +++ b/src/java/com/threerings/presents/server/PresentsClient.java @@ -874,8 +874,8 @@ public class PresentsClient public void eventReceived (DEvent event) { if (event instanceof PresentsDObjectMgr.AccessObjectEvent) { - log.warning("Ignoring event that shouldn't be forwarded " + event + "."); - Thread.dumpStack(); + log.warning("Ignoring event that shouldn't be forwarded " + event + ".", + new Exception()); return; } diff --git a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java index 52a7985fc..645b62953 100644 --- a/src/java/com/threerings/presents/server/PresentsDObjectMgr.java +++ b/src/java/com/threerings/presents/server/PresentsDObjectMgr.java @@ -218,9 +218,8 @@ public class PresentsDObjectMgr public T registerObject (T object) { if (_dobjThread != null && !isDispatchThread()) { - log.warning("Registering DObject on non-dobject thread: " + - "[class=" + object.getClass().getName() + "]"); - Thread.dumpStack(); + log.warning("Registering DObject on non-dobject thread", + "class", object.getClass().getName(), new Exception()); } int oid = getNextOid(); diff --git a/src/java/com/threerings/presents/server/net/Connection.java b/src/java/com/threerings/presents/server/net/Connection.java index e2a2999bd..96f9219ea 100644 --- a/src/java/com/threerings/presents/server/net/Connection.java +++ b/src/java/com/threerings/presents/server/net/Connection.java @@ -166,8 +166,7 @@ public abstract class Connection implements NetEventHandler { // we shouldn't be closed twice if (isClosed()) { - log.warning("Attempted to re-close connection " + this + "."); - Thread.dumpStack(); + log.warning("Attempted to re-close connection " + this + ".", new Exception()); return; } @@ -186,8 +185,7 @@ public abstract class Connection implements NetEventHandler { // if we're already closed, then something is seriously funny if (isClosed()) { - log.warning("Failure reported on closed connection " + this + "."); - Thread.dumpStack(); + log.warning("Failure reported on closed connection " + this + ".", new Exception()); return; } diff --git a/src/java/com/threerings/presents/server/net/ConnectionManager.java b/src/java/com/threerings/presents/server/net/ConnectionManager.java index f21b3454d..d44d1d79d 100644 --- a/src/java/com/threerings/presents/server/net/ConnectionManager.java +++ b/src/java/com/threerings/presents/server/net/ConnectionManager.java @@ -847,16 +847,14 @@ public class ConnectionManager extends LoopingThread { // sanity check if (conn == null || msg == null) { - log.warning("postMessage() bogosity [conn=" + conn + ", msg=" + msg + "]."); - Thread.dumpStack(); + log.warning("postMessage() bogosity", "conn", conn, "msg", msg, new Exception()); return; } // more sanity check; messages must only be posted from the dobjmgr thread if (!_omgr.isDispatchThread()) { - log.warning("Message posted on non-distributed object thread [conn=" + conn + - ", msg=" + msg + ", thread=" + Thread.currentThread() + "]."); - Thread.dumpStack(); + log.warning("Message posted on non-distributed object thread", "conn", conn, + "msg", msg, "thread", Thread.currentThread(), new Exception()); // let it through though as we don't want to break things unnecessarily } diff --git a/src/java/com/threerings/presents/util/SafeSubscriber.java b/src/java/com/threerings/presents/util/SafeSubscriber.java index 1b01c21f3..9872ffc3b 100644 --- a/src/java/com/threerings/presents/util/SafeSubscriber.java +++ b/src/java/com/threerings/presents/util/SafeSubscriber.java @@ -76,8 +76,7 @@ public class SafeSubscriber public void subscribe (DObjectManager omgr) { if (_active) { - log.warning("Active safesub asked to resubscribe " + this + "."); - Thread.dumpStack(); + log.warning("Active safesub asked to resubscribe " + this + ".", new Exception()); return; } @@ -88,8 +87,7 @@ public class SafeSubscriber // logically impossible) if (_object != null) { log.warning("Incroyable! A safesub has an object and was " + - "non-active!? " + this + "."); - Thread.dumpStack(); + "non-active!? " + this + ".", new Exception()); // make do in the face of insanity _subscriber.objectAvailable(_object); return; @@ -125,8 +123,7 @@ public class SafeSubscriber if (_object == null && !_pending) { return; } - log.warning("Inactive safesub asked to unsubscribe " + this + "."); - Thread.dumpStack(); + log.warning("Inactive safesub asked to unsubscribe " + this + ".", new Exception()); } // note that we no longer desire to be subscribed @@ -136,8 +133,7 @@ public class SafeSubscriber // make sure we don't have an object reference if (_object != null) { log.warning("Incroyable! A safesub has an object and is " + - "pending!? " + this + "."); - Thread.dumpStack(); + "pending!? " + this + ".", new Exception()); } else { // nothing to do but wait for the subscription to complete // at which point we'll pitch the object post-haste @@ -148,8 +144,7 @@ public class SafeSubscriber // make sure we have our object if (_object == null) { log.warning("Zut alors! A safesub _was_ active and not " + - "pending yet has no object!? " + this + "."); - Thread.dumpStack(); + "pending yet has no object!? " + this + ".", new Exception()); // nothing to do since we're apparently already unsubscribed return; } diff --git a/src/java/com/threerings/util/MessageBundle.java b/src/java/com/threerings/util/MessageBundle.java index 69f5597ec..87678913f 100644 --- a/src/java/com/threerings/util/MessageBundle.java +++ b/src/java/com/threerings/util/MessageBundle.java @@ -247,9 +247,7 @@ public class MessageBundle } if (reportMissing) { - log.warning("Missing translation message " + - "[bundle=" + _path + ", key=" + key + "]."); - Thread.dumpStack(); + log.warning("Missing translation message", "bundle", _path, "key", key, new Exception()); } return null; @@ -319,9 +317,8 @@ public class MessageBundle } } else { - log.warning("Missing translation message " + - "[bundle=" + _path + ", key=" + key + "]."); - Thread.dumpStack(); + log.warning("Missing translation message", "bundle", _path, "key", key, + new Exception()); } } diff --git a/src/java/com/threerings/util/TimeUtil.java b/src/java/com/threerings/util/TimeUtil.java index fc84877dc..779834b63 100644 --- a/src/java/com/threerings/util/TimeUtil.java +++ b/src/java/com/threerings/util/TimeUtil.java @@ -47,10 +47,9 @@ public class TimeUtil protected static final byte MAX_UNIT = DAY; /** - * Get a translatable string specifying the magnitude of the specified - * duration. Results will be between "1 second" and "X hours", with - * all times rounded to the nearest unit. "0 units" will never be - * displayed, the minimum is 1. + * Get a translatable string specifying the magnitude of the specified duration. Results will + * be between "1 second" and "X hours", with all times rounded to the nearest unit. "0 units" + * will never be displayed, the minimum is 1. */ public static String getTimeOrderString (long duration, byte minUnit) { @@ -58,12 +57,11 @@ public class TimeUtil } /** - * Get a translatable string specifying the magnitude of the specified - * duration, with the units of time bounded between the minimum and - * maximum specified. "0 units" will never be returned, the minimum is 1. + * Get a translatable string specifying the magnitude of the specified duration, with the units + * of time bounded between the minimum and maximum specified. "0 units" will never be returned, + * the minimum is 1. */ - public static String getTimeOrderString ( - long duration, byte minUnit, byte maxUnit) + public static String getTimeOrderString (long duration, byte minUnit, byte maxUnit) { // enforce sanity minUnit = (byte) Math.min(minUnit, maxUnit); @@ -85,8 +83,7 @@ public class TimeUtil } /** - * Get a translatable string specifying the duration, down to the - * minimum granularity. + * Get a translatable string specifying the duration, down to the minimum granularity. */ public static String getTimeString (long duration, byte minUnit) { @@ -117,8 +114,7 @@ public class TimeUtil } /** - * Internal method to get the quantity for the specified unit. - * (Not very OO) + * Internal method to get the quantity for the specified unit. (Not very OO) */ protected static int getQuantityPerUnit (byte unit) { @@ -132,8 +128,7 @@ public class TimeUtil } /** - * Internal method to get the translation key for the specified unit. - * (Not very OO) + * Internal method to get the translation key for the specified unit. (Not very OO) */ protected static String getTransKey (byte unit) {