Thanks for review, Junping and Devaraj.
If System.currentTimeMillis() < started, then we can return -1 or 0 instead
IMHO, Times#elapsed is to computed the delta between two timestamps: started and finished. Given System.currentTimeMillis() < started <= finished, it still should be a valid case. To make sure the elapsed time should always be non-negative, we need to check started <= finished, and return -1 if not.
(and log a warn that clock not getting synchronized)
Adding a warning/info message before making it as 0 would help to diagnose/find out the issues if any.
Also adding a test in TestTimes.java could be a good idea.
Sounds a good idea. Will address it in the new patch.
In addition, add a code comment to explicitly declare the behavior of Times#elapsed