Here is the code snippet:
public InstrumentPriceEngine(final JForexPlatform jforexPlatform,
final Instrument instrument) {
history = checkNotNull(jforexPlatform.getHistory());
this.instrument = checkNotNull(instrument);
lastValidTick = new EmptyTick();
}
public synchronized ITick getLastTick() {
final ITick tempTick = getLastTickFromHistory();
if (tempTick != null)
lastValidTick = tempTick;
return lastValidTick;
}
private ITick getLastTickFromHistory() {
ITick tick = null;
try {
tick = history.getLastTick(instrument);
} catch (JFException e) {
logger.warn("Could not receive last tick for " + instrument.toString() + ". Error message: " + e.getMessage());
}
return tick;
}
The InstrumentPriceEngine is the class constructor. The field lastValidTick is the tick container and the policy is that if an error occures within IHistory always the last known price is returned.
Therefore in getLastTick a temporary variable saves the result to the real call.
This is the revised code with the null check added. I tested it with internet disconnection and it works as expected. Without testing for null, the returned tick maybe null and is dangerous.
I was just wondering why in the documentation of IHistory.getLastTick it is not stated that the method can also return null?
Thanks,
Juergen