eclipse / tm4e

TextMate support in Eclipse IDE
https://projects.eclipse.org/projects/technology.tm4e
Eclipse Public License 2.0
79 stars 54 forks source link

ConcurrentModificationException if tm4e used in the context of diff editor #743

Closed iloveeclipse closed 1 month ago

iloveeclipse commented 3 months ago

Switching different merge viewers in diff editor can cause following exception (I see it in debugger, not in the error log)

java.util.ConcurrentModificationException
    at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1229)
    at org.eclipse.tm4e.core.internal.grammar.BasicScopeAttributesProvider.getBasicScopeAttributes(BasicScopeAttributesProvider.java:56)
    at org.eclipse.tm4e.core.internal.grammar.Grammar.getMetadataForScope(Grammar.java:112)
    at org.eclipse.tm4e.core.internal.grammar.AttributedScopeStack._pushAttributed(AttributedScopeStack.java:172)
    at org.eclipse.tm4e.core.internal.grammar.AttributedScopeStack.pushAttributed(AttributedScopeStack.java:157)
    at org.eclipse.tm4e.core.internal.grammar.LineTokenizer.scanNext(LineTokenizer.java:194)
    at org.eclipse.tm4e.core.internal.grammar.LineTokenizer.scan(LineTokenizer.java:131)
    at org.eclipse.tm4e.core.internal.grammar.LineTokenizer.tokenizeString(LineTokenizer.java:565)
    at org.eclipse.tm4e.core.internal.grammar.Grammar._tokenize(Grammar.java:342)
    at org.eclipse.tm4e.core.internal.grammar.Grammar.tokenizeLine(Grammar.java:259)
    at org.eclipse.tm4e.core.model.TMTokenizationSupport.tokenize(TMTokenizationSupport.java:80)
    at org.eclipse.tm4e.core.model.TMModel$TokenizerThread.revalidateTokens(TMModel.java:249)
    at org.eclipse.tm4e.core.model.TMModel$TokenizerThread.run(TMModel.java:172)

Shouldn't org.eclipse.tm4e.core.internal.grammar.BasicScopeAttributesProvider.cache be a ConcurrenthashMap?

On the shell I see this:

Apr 09, 2024 7:02:09 PM org.eclipse.tm4e.core.model.TMModel$TokenizerThread revalidateTokens
SEVERE: java.util.ConcurrentModificationException
sebthom commented 3 months ago

Yes, we can make it a ConcurrentHashMap. The code was originally translated from TypeScript where it runs single threaded.

sebthom commented 3 months ago

Please try out the latest snapshot.

iloveeclipse commented 3 months ago

Please try out the latest snapshot.

Looks good so far.

BTW, I've pimped SDK so the Textmate works now also by default in compare editor, see https://github.com/eclipse-platform/eclipse.platform.ui/issues/1747

sebthom commented 1 month ago

TM4E 0.12.0 incorporating the fix released