forked from I2P_Developers/i2p.i2p
Jetty: backport patch from 9.4.4 to 9.2.21
to fix Timer crash in RolloverFileOutputStream
1e46576bf4
https://github.com/eclipse/jetty.project/issues/1469
This commit is contained in:
@ -62,6 +62,8 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
||||
private boolean _append;
|
||||
private int _retainDays;
|
||||
|
||||
private final TimeZone _zone;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param filename The filename must include the string "yyyy_mm_dd",
|
||||
@ -166,27 +168,28 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
||||
_retainDays=retainDays;
|
||||
setFile();
|
||||
|
||||
_zone = zone;
|
||||
synchronized(RolloverFileOutputStream.class)
|
||||
{
|
||||
if (__rollover==null)
|
||||
__rollover=new Timer(RolloverFileOutputStream.class.getName(),true);
|
||||
|
||||
_rollTask=new RollTask();
|
||||
|
||||
midnight = Calendar.getInstance();
|
||||
midnight.setTimeZone(zone);
|
||||
// set to midnight
|
||||
midnight.set(Calendar.HOUR, 0);
|
||||
midnight.set(Calendar.MINUTE, 0);
|
||||
midnight.set(Calendar.SECOND, 0);
|
||||
midnight.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
scheduleNextRollover();
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleNextRollover()
|
||||
{
|
||||
_rollTask=new RollTask();
|
||||
|
||||
midnight = Calendar.getInstance();
|
||||
midnight.setTimeZone(_zone);
|
||||
// set to midnight
|
||||
midnight.set(Calendar.HOUR, 0);
|
||||
midnight.set(Calendar.MINUTE, 0);
|
||||
midnight.set(Calendar.SECOND, 0);
|
||||
midnight.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
// Increment to next day.
|
||||
// Using Calendar.add(DAY, 1) takes in account Daylights Savings
|
||||
// differences, and still maintains the "midnight" settings for
|
||||
@ -322,7 +325,10 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
||||
_file=null;
|
||||
}
|
||||
|
||||
_rollTask.cancel();
|
||||
if (_rollTask != null)
|
||||
{
|
||||
_rollTask.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -338,10 +344,10 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
||||
RolloverFileOutputStream.this.scheduleNextRollover();
|
||||
RolloverFileOutputStream.this.removeOldFiles();
|
||||
}
|
||||
catch(IOException e)
|
||||
catch(Throwable t)
|
||||
{
|
||||
// Cannot log this exception to a LOG, as RolloverFOS can be used by logging
|
||||
e.printStackTrace(System.err);
|
||||
t.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user