archi icon indicating copy to clipboard operation
archi copied to clipboard

Stack overflow when using If label expression with long text string

Open olwol opened this issue 2 years ago • 8 comments

Version of Archi

4.9.1 - here I don't have the problem 4.9.3 - here I have the problem

Archi Plug-ins

coArchi 0.8.3.202204051232 jArchi 1.2.0.202110121451

Operating System

Windows 10

Expected Behaviour

The views named 1, 2, 3 and 4 from my model created for trouble shooting should show.

Actual Behaviour

image

Open view shows a red button and the message "Failed to create the part's controls"

Steps to Reproduce the Behaviour

I have copied the failing views from my model into a model I can share with you and I used script "Anonymize". You just need to open the views to get the error. If you want me to send the model, how can I do so?

olwol avatar Jun 05 '22 17:06 olwol

Yes please send the model to info at archimatetool.com and also the error log.

The Error Log can be accessed in Archi by selecting the “About Archi” menu item. In the dialog box press the “Installation Details” button, then select the “Configuration” tab and press the “View Error Log” button.

Phillipus avatar Jun 05 '22 17:06 Phillipus

Thanks for the model which I've analysed.

  1. There is a stack overflow error caused by an infinite loop in the Label Renderer
  2. The model opens in Archi 4.9.1 but not 4.9.2 or 4.9.3
  3. Changes made in this commit have led to the regression: https://github.com/archimatetool/archi/commit/16893d425b3cccbe97f161ec04c10990e0a0c8a9
  4. The model contains many uses of the expression if:${documentation} and this leads to infinite loops

Phillipus avatar Jun 05 '22 18:06 Phillipus

The strange thing is if I replace all documentation fields with placeholder text like "Some text" the error doesn't occur.

Phillipus avatar Jun 05 '22 18:06 Phillipus

I've narrowed it down to a simple reproducible model test case (attached here). It's caused by a combination of a long documentation field and this label expression leading to stack overflow:

${if:${documentation}:${documentation}}

test.zip

In IfRenderer it gets into an infinite loop at line 66:

private String renderIfThenElse(String text) {
    Matcher matcher = IF_THEN_ELSE_PATTERN.matcher(text);

    while(matcher.find()) { // <------ HERE
        String ifCondition = matcher.group("IF");

If the text in the documentation field is edited to reduce its length by half the problem does not occur.

@jbsarrodie Hi JB! Would you be able to investigate? 🙏

Phillipus avatar Jun 05 '22 19:06 Phillipus

Something to do with these lines in IfRenderer:

private static final String acceptedChar = "(?:[^:\\}\\\\]|\\\\:|\\\\\\\\)";
private static final String textWithoutExpressions = "(?:\\\\:|" + notStartOfExpression + acceptedChar + ")*";

Phillipus avatar Jun 05 '22 19:06 Phillipus

A simpler way to reproduce:

${if:A long text string:Hello}

Where "A long text string" is replaced by a long text string (say > 1000 chars or more)

Phillipus avatar Jun 07 '22 12:06 Phillipus

I can't fix this so for the next version of Archi any errors will be caught and shown in the view as "Label Expression Error" At least you'll be able to open the View.

Phillipus avatar Jun 18 '22 08:06 Phillipus

@jbsarrodie Hi JB! Would you be able to investigate?

Sorry, for strange reasons, notifications for this issue were routed to my spam folder, so discovering it only now. I'll look at it this week.

jbsarrodie avatar Jun 18 '22 18:06 jbsarrodie