archimatetool / archi

Archi: ArchiMate Modelling Tool
https://www.archimatetool.com
MIT License
916 stars 267 forks source link

Stack overflow when using If label expression with long text string #849

Open olwol opened 2 years ago

olwol commented 2 years ago

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?

Phillipus commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

Phillipus commented 2 years ago

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 commented 2 years ago

Something to do with these lines in IfRenderer:

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

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 commented 2 years ago

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.

jbsarrodie commented 2 years ago

@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.