enhancement
major
minor
defect
critical
major
minor
minor
#30089
The TL script functions `binarySize()` and `modelHealthReset()` return integers instead of doubles and log an error on every call
Description
The TL-Script function binarySize() (class BinaryFunctions, prefix binary) returns the size of a binary value as a java.lang.Long. However, TL-Script requires Double for numbers. AlthoughSearchExpression.internalCheckValue() converts the value, it logs an error with a stack trace on every call:
Numbers in TL-Script must be represented as Double only. Use SearchExpression.toNumber() before returning a number from a TL-Script function.
The result of the function itself is correct. However, because the error is logged, any test that interprets the error in the log as a failure—such as ScriptedTest or ApplicationTestSetup ("An error was logged during the test execution!")—will abort.
The same applies to the TL-Script function `modelHealthReset() ` (class ` AIScriptFunctions`, ` tl-ai-core`), which returns the number of reset markers as an `int `.
Cause
com.top_logic.model.search/src/main/java/com/top_logic/model/search/expr/config/operations/BinaryFunctions.java, line 76f.:
{{{#!java public static Long size(@Mandatory BinaryDataSource data) { return data == null ? null : Long.valueOf(data.getSize()); } }}}
Check in com.top_logic.model.search/src/main/java/com/top_logic/model/search/expr/SearchExpression.java, line 141 and following (internalCheckValue): Integer, Long, Short, and Byte are logged as errors.
Reproduction
- A model type with a ` data ` attribute of type `tl.core:Binary ` and a derived attribute:
{{{#!xml <property name="size" type="tl.core:Long"> <annotations> <storage-algorithm> <query expr="d -> binarySize($d.get(my.module:Document#data))"/> </storage-algorithm> </annotations> </property> }}}
- Create an object with an uploaded file and display the size, e.g., as a table column.
- The log shows the above-mentioned error for every calculation.
This can be reproduced directly even with any TL script expression, e.g., ` binarySize(binary("x")).`
Expected behavior
binarySize() returns a Double (or -1.0 if the size is unknown) without an error being logged.
Workaround
Do not display the "Size" column.
Solution
- BinaryFunctions.size() (binarySize()) returns a Double via SearchExpression.toNumber().
- AIScriptFunctions.modelHealthReset() also returns the number of reset markers as a Double. A review of all TLScriptFunctions subclasses revealed no other functions with an integer return type.
- AbstractSearchExpressionTest.evalWithoutErrors() evaluates an expression and fails if an error was logged during the process; this highlights contract violations that do not alter the result but are only recorded in the log.
Test: TestBinaryFunctions.testSize (tl-model-search).