Ho il seguente codice in cui assegno il risultato di un metodo Java a una variabile freemarker.Come posso assegnare una variabile da un metodo che potrebbe restituire nulla?
<#assign singleBenchmark = solverBenchmark.findSingleBenchmark(problemBenchmark)>
Il problema è che il valore di ritorno di questo metodo Java potrebbe null
. E anche se verifico se questa variabile non è null
:
<#if !singleBenchmark??>
<td></td>
<#else>
<td>${singleBenchmark.score}</td>
</#if>
Si blocca ancora sulla linea <#assign ...>
se questo metodo Java ritorna null
, con questa eccezione:
freemarker.core.InvalidReferenceException: Error on line 109, column 45 in index.html.ftl
solverBenchmark.findSingleBenchmark(problemBenchmark) is undefined.
It cannot be assigned to singleBenchmark
at freemarker.core.Assignment.accept(Assignment.java:111)
Come posso evitare questa eccezione senza dover chiamare il metodo findSingleBenchmark
più volte nel mio ftl?