From cf3c6456239f51d70be3fe3edbd04d57c6b26400 Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Mon, 26 Dec 2016 17:18:33 +0300 Subject: [PATCH] Check for system time jump back (logging only) --- .../src/com/intellij/ide/IdeEventQueue.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index 9610ccbdd8a5..100b7b72e702 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -114,6 +114,7 @@ public class IdeEventQueue extends EventQueue { private boolean myIsInInputEvent; private AWTEvent myCurrentEvent; private long myLastActiveTime; + private long myLastEventTime = System.currentTimeMillis(); private WindowManagerEx myWindowManager; private final List myDispatchers = ContainerUtil.createLockFreeCopyOnWriteList(); private final List myPostProcessors = ContainerUtil.createLockFreeCopyOnWriteList(); @@ -338,6 +339,7 @@ public class IdeEventQueue extends EventQueue { @Override public void dispatchEvent(@NotNull AWTEvent e) { + checkForTimeJump(); if (!appIsLoaded()) { try { super.dispatchEvent(e); @@ -382,6 +384,15 @@ public class IdeEventQueue extends EventQueue { } } + //As we rely on system time monotonicity in many places let's log anomalies at least. + private void checkForTimeJump() { + long now = System.currentTimeMillis(); + if (myLastEventTime > now + 1000) { + LOG.error("System clock's jumped back by ~" + (myLastEventTime - now) / 1000 + " sec"); + } + myLastEventTime = now; + } + private static boolean isInputEvent(@NotNull AWTEvent e) { return e instanceof InputEvent || e instanceof InputMethodEvent || e instanceof WindowEvent || e instanceof ActionEvent; }