Scott Murphy Heiberg created GROOVY-12532:
---------------------------------------------
Summary: Parallel parsing corrupts the shared ErrorCollector's
message list
Key: GROOVY-12532
URL: https://issues.apache.org/jira/browse/GROOVY-12532
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 6.0.0
Reporter: Scott Murphy Heiberg
{{CompilationUnit.compile}} parses the sources of a unit in parallel when there
is more than one and the {{parallelParse}} optimization option is on, which it
is by default ({{groovy.parallel.parse}}). All sources share the unit's
{{ErrorCollector}}, which keeps errors and warnings in plain {{LinkedList}}s
and adds to them without synchronization. When several sources report errors at
once, the list gets corrupted:
{code:groovy}
import org.codehaus.groovy.control.*
int corrupt = 0
300.times { r ->
def unit = new CompilationUnit()
64.times { i -> unit.addSource("S${r}_${i}.groovy", "class S${r}_${i} { def
m() { foo( } }") }
try { unit.compile(Phases.CONVERSION) } catch (CompilationFailedException
ignored) { }
def errors = unit.errorCollector.errors
int linked = 0
try { for (e in errors) linked++ } catch (e) { corrupt++; return }
if (linked != errors.size()) corrupt++
}
assert corrupt == 0 // fails: 85 of 300 on 6.0.0, 96 on master
{code}
The list's {{size()}} no longer matches its elements, so copying it can throw.
This failed a {{groovy-lsp}} test on CI, where {{CompiledDocument}} copies the
errors of a compile:
{noformat}
LanguageQualityTest > dotCompletionListsReceiverMembers() FAILED
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
at java.base/java.util.LinkedList.toArray(LinkedList.java:1065)
at java.base/java.util.ArrayList.<init>(ArrayList.java:182)
at
org.apache.groovy.lsp.internal.compile.CompiledDocument.<init>(CompiledDocument.java:66)
at
org.apache.groovy.lsp.internal.compile.GroovyCompiler.addCompiled(GroovyCompiler.java:278)
{noformat}
Which and how many errors are reported also depends on thread timing: with
{{-Dgroovy.parallel.parse=false}} the example always reports one error and the
assertion passes, while with parallel parsing the count varies from run to run.
Seen in 4.0.33, 5.0.8, 6.0.0 and master.
Expected: the collected messages stay consistent when sources are parsed in
parallel.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)