Error to read .HistoricItem.getState() on null

Hello everyone!
I’m using OH 2.5. I’ll bring up the topic because I still can’t find an answer to a similar question. I save the data to the rrd4 database according to the strategy once a minute. But some of the data is missing due to the periodic shutdown of the computer. When trying to read using .historicState(parse(My_String)).state as Number an error occurs .persistence.HistoricItem.getState() on null. How do I make a condition correctly so that the error does not occur and the rule continues to be executed?.

The syntax

if (Total_act.historicState(parse(Int_nowY.toString() + "-" + Int_nowM.toString() + "-04T12:00:00.0000")).state != null)

doesn’t work

Please correct the title of your topic, as it is not cloud related.

Like with about any programming, you must check for the returned object .historicState(parse(My_String)) to not be null before you try to access it i.e. .state

That’s the question: what is the correct syntax for this condition?

Come on, I almost wrote it down, didn’t I. Make it two lines add a check for null.

I’m sorry, I just didn’t get it right away.
Syntax:

if (Total_act.historicState(parse(Total_String)) != null) {
    Cht_at7 = Total_act.historicState(parse(Total_String)).state as Number
}

it works! Thanks!