Author: toad
Date: 2006-12-15 20:11:16 +0000 (Fri, 15 Dec 2006)
New Revision: 11418
Modified:
trunk/freenet/src/freenet/support/FileLoggerHook.java
Log:
Handle an impossible crash.
Modified: trunk/freenet/src/freenet/support/FileLoggerHook.java
===================================================================
--- trunk/freenet/src/freenet/support/FileLoggerHook.java 2006-12-15
17:27:57 UTC (rev 11417)
+++ trunk/freenet/src/freenet/support/FileLoggerHook.java 2006-12-15
20:11:16 UTC (rev 11418)
@@ -20,6 +20,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
+import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.Vector;
@@ -823,6 +824,7 @@
private static final int LINE_OVERHEAD = 60;
public void logString(byte[] b) {
+ int noElementCount = 0;
synchronized (list) {
int sz = list.size();
list.add(b);
@@ -831,7 +833,19 @@
if ((list.size() > MAX_LIST_SIZE) || (listBytes >
MAX_LIST_BYTES)) {
while ((list.size() > (MAX_LIST_SIZE * 0.9F))
|| (listBytes > (MAX_LIST_BYTES *
0.9F))) {
- byte[] ss = (byte[])
(list.removeFirst());
+ byte[] ss;
+ try {
+ ss = (byte[])
(list.removeFirst());
+ } catch (NoSuchElementException e) {
+ // Yes I know this is
impossible but it happens with 1.6
+ noElementCount++;
+ if(noElementCount > 1000) {
+
System.err.println("Lost log line because of constant
NoSuchElementException's");
+ e.printStackTrace();
+ return;
+ }
+ continue;
+ }
listBytes -= (ss.length +
LINE_OVERHEAD);
x++;
}