closed SyntaxChecker#checkSyntax is not thread safe

0 votes
asked Mar 17, 2015 in Bug by krasa (820 points)
closed Mar 17, 2015 by krasa

version 8021

It seems that rendering in another thread affects result of #checkSyntax

I had this piece of code return 3 different values: 2, 7, 10

SyntaxResult syntaxResult = SyntaxChecker.checkSyntax("@startuml\n" +
        "\n" +
        "!include ss.puml \n" +
        "\n" +
        "j\n" +
        "List <|.. Argfjhfgjf\n" +
        "\n" +
        "@enduml");
System.err.println(syntaxResult.getErrorLinePosition());

http://i.imgur.com/vR1RJxT.png

Perhaps it has something to do with the loading of the file.


 

 

 

closed with the note: the problem was in client code and wrong handling of FileSystem#currentDir while using pooled threads.

1 Answer

0 votes
answered Mar 17, 2015 by plantuml (295,000 points)
selected Jun 16, 2015 by krasa
 
Best answer

Hello,

Thanks for your tests and for the report.

We are not sure to have found the real reason why it is not thread-safe.
However, we've build a new beta that put a global lock during file reading, so that it should be thread safe now.

https://dl.dropboxusercontent.com/u/13064071/plantuml.jar

We still have to investigate to understand what's going on and to provide a better solution.
Tell us if it's working for you.

Regards,
 

commented Mar 17, 2015 by krasa (820 points)
Hi, it did not help. I tried some older versions and it behaved the same even in 7982. I will try to create some quickstart or debug it.
commented Mar 17, 2015 by krasa (820 points)
I've got it. The problem is net.sourceforge.plantuml.FileSystem#setCurrentDir,
one thread was changing it back and forth, but the thread with SyntaxChecker was not. So that the file was included once, then not, and sometimes it included an old content (more on that below).
So the problem was mainly on our side, although  I should maybe synchronize the usage of rendering and syntax checking, since the currentDir is set on several places in the PlantUml.

But that reminds me another problem, PlantUml is looking into the physical file, but IntelliJ saves changes from the editor only after some actions, and there is really no easy way what to do about it. I would either need to parse the file and trigger commit for for its includes, or PlantUml would need to provide some extension for reading files - some hook before reading the file, or the reader itself.

And the last problem, the SyntaxChecker returns an error line number from the diagram with inlined includes, so if I wanted to show errors, I would have to inline it manually, and compute which line corresponds to a line in the editor, currently I just get error on line 10, when there are only 8 lines...

What do you think?

Cheers.
...