log4j does not guarantee monotonically increasing date values

This commit is contained in:
2016-12-10 15:35:29 +01:00
parent 34ee64fff1
commit 4376f8f783

View File

@@ -4,9 +4,12 @@ import java.io.BufferedOutputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.logging.Logger;
class PdbWriter implements AutoCloseable { class PdbWriter implements AutoCloseable {
private final static Logger LOGGER = Logger.getLogger(PdbWriter.class.getCanonicalName());
private static final boolean APPEND = true; private static final boolean APPEND = true;
private final OutputStream outputStream; private final OutputStream outputStream;
private final PdbFile pdbFile; private final PdbFile pdbFile;
@@ -29,10 +32,11 @@ class PdbWriter implements AutoCloseable {
} }
public void write(final Entry entry) throws WriteException { public void write(final Entry entry) throws WriteException {
// System.out.println(entry);
write(entry.getEpochMilli(), entry.getValue()); write(entry.getEpochMilli(), entry.getValue());
} }
void write(final long epochMilli, final long value) throws WriteException { private void write(final long epochMilli, final long value) throws WriteException {
final long offsetEpochMilli = pdbFile.getOffsetInEpochMilli(); final long offsetEpochMilli = pdbFile.getOffsetInEpochMilli();
final long adjustedValue = epochMilli - offsetEpochMilli; final long adjustedValue = epochMilli - offsetEpochMilli;
assertValueInRange(adjustedValue); assertValueInRange(adjustedValue);
@@ -46,7 +50,10 @@ class PdbWriter implements AutoCloseable {
private void assertEpochMilliInRange(final long epochMilli) { private void assertEpochMilliInRange(final long epochMilli) {
if (epochMilli < minimalEpochMilli) { if (epochMilli < minimalEpochMilli) {
throw new IllegalArgumentException("value must not be smaller than: " + minimalEpochMilli); LOGGER.warning("epochMilli must not be smaller than " + minimalEpochMilli + ", but was " + epochMilli
+ ". We'll accept this for now. "
+ "Currently there is no code that relies on monotonically increasing date values. "
+ "Log4j does not guarantee it either.");
} }
} }