Description sizes and their booleans

Hi all,

I have encountered a peculiar problem after updating from M2Doc 3.1.1 to 3.2.0.
In my template, I want to list the descriptions of capability realizations IF they have a description. So I use the following code

{m:if (capabilityRealization.description.size() <> 0)}
{m:capabilityRealization.description.fromHTMLBodyString()}
{m:else}
No description.
{m:endif}

This worked fine before the update. But after the update, the if condition get’s evaluated as true, even if the description size is zero (checked in the model, in the M2Doc interpreter, and had it printed in the template). However: If I use ->size() instead of .size() it works.

I’m of course happy that I have a working template again, but I was wondering if this is how it’s supposed to work or not.

Also: When using the M2Doc interpreter it to evaluate statements like capabilityRealization.description = null it returns ‘true’ for elements with empty descriptions but ‘false’ if you evaluate this statement in the Word template.

I don’t reproduce the behavior you describe here using Capella 5.1.0 and M2Doc 3.2.0. I used the following template:

{m:let comp = self.eAllContents(la::LogicalComponent)->at(1)}
{m:comp.description}
{m:comp.description = null}
{m:comp.description.size()}
{m:comp.description.size() <> 0}
{m:''.size()}
{m:''.size() <> 0}
{m:endlet}

And it generate the following result:

[empty line for a null desciption]
true
0
false
0
false

The call .size() returns the size of the given String, if the String is null than an empty String is used. But the ->size() will return the size of a Collection and is the given element is a scalar it will be put inside a Sequence. In the process if the value is null it will not be added to the resulting Sequence. So the following will happen:

{m:null->size()} return 0
{m:''->size()} return 1

And that’s probably not what you want.
I think that when you edit the description it’s no longer null and if you empty it it becomes an empty String and not the initial null value.

1 Like

I checked it again on my side and you are completely right. Probably tunnel vision got the best of me.

Thanks again for the quick and extensive answer.

I have been there :slight_smile:
You are welcome