ArrayIndexOutOfBoundsException after selection change or reference resolution
I sometimes get ArrayIndexOutOfBoundsException after selection changes or on reference resolution, like:
Internal error evaluating editor-properties (ArrayIndexOutOfBoundsException; see error log) rewriting failed Internal error evaluating editor-resolve (ArrayIndexOutOfBoundsException; see error log) Internal error evaluating editor-resolve (ArrayIndexOutOfBoundsException; see error log) Internal error evaluating editor-properties (ArrayIndexOutOfBoundsException; see error log) rewriting failed, trace: Internal error evaluating editor-properties (ArrayIndexOutOfBoundsException; see error log) rewriting failed, trace: position_of_term_1_1
The error log contains no information.
Submitted by Gabriël Konat on 28 March 2014 at 11:15
Issue Log
I experience the same error
Internal error evaluating editor-properties (ArrayIndexOutOfBoundsException; see error log) rewriting failed, trace: position_of_term_1_0 position_of_term_1_1 position_of_term_1_1
The java stack trace is not really informative:
java.lang.ArrayIndexOutOfBoundsException
I’ve also got it for the outline
Internal error evaluating outline (ArrayIndexOutOfBoundsException; see error log) rewriting failed, trace: position_of_term_1_0 position_of_term_1_1 position_of_term_1_1
The
editor-properties
andeditor-resolve
use more or less the same code. But theoutline
uses completely different strategies. So the error seems to be somewhere else.
Is this with the latest nightly? I thought I fixed this yesterday. I cannot reproduce it either.
Yes:
Spoofax Core 1.2.0.0-s41333
Yes, running the same version as Daco. The weird thing is that it only seems to happen once per Eclipse instance, or once per build, and only sometimes in some languages. The easiest way I can reproduce it is to close Eclipse, start it again, and immediately start selecting text (dragging the mouse around in the file) in my editor for the QL language (https://github.com/metaborg/lwc2013/tree/master/org.spoofax.lang.lwc.ql2)
I got more information about the exceptions in my error log this time, 6 of them. Might this be related to https://yellowgrass.org/issue/Spoofax/757, I got 6 exceptions there as well while trying to reproduce this error, some mentioning position of term (see my latest comment). Here’s the stacktraces that I got, it shows
ArrayIndexOutOfBoundsException
where the index is negative, which will always fail of course.Internal error evaluating strategy editor-properties editor_properties_0_0 get_all_editor_properties_1_2 target_prop_1_0 pp_ast_1_0 z_112972 prettyprint_Start_0_0 pp_one_Z_1_0 pp_one_1_0 m_112965 pp_V_list_1_1 map_1_0 pp_one_V_1_0 pp_one_1_0 m_112965 pp_one_Z_1_0 pp_one_1_0 m_112965 java.lang.ArrayIndexOutOfBoundsException: -4 at org.spoofax.interpreter.core.StackTracer.push(StackTracer.java:39) at org.strategoxt.stratego_lib.set_config_0_0.invoke(set_config_0_0.java:21) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:816) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:807) at org.strategoxt.imp.runtime.services.StrategoObserver.invoke(StrategoObserver.java:614) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:695) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:686) at org.strategoxt.imp.runtime.services.views.properties.PropertiesService.getProperties(PropertiesService.java:90) at org.strategoxt.imp.runtime.editor.StrategoTermSelection.getFirstElement(StrategoTermSelection.java:68) at org.strategoxt.imp.runtime.editor.SpoofaxEditor$3.run(SpoofaxEditor.java:109) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53) Internal error evaluating strategy editor-properties editor_properties_0_0 get_all_editor_properties_1_2 target_prop_1_0 pp_ast_1_0 z_112972 prettyprint_Start_0_0 pp_one_Z_1_0 pp_one_1_0 m_112965 pp_V_list_1_1 map_1_0 pp_one_V_1_0 pp_one_1_0 m_112965 pp_one_Z_1_0 pp_one_1_0 m_112965 pp_one_Z_1_0 pp_one_1_0 m_112965 java.lang.ArrayIndexOutOfBoundsException: -6 at org.spoofax.interpreter.core.StackTracer.push(StackTracer.java:39) at org.strategoxt.stratego_lib.set_config_0_0.invoke(set_config_0_0.java:21) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:816) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:807) at org.strategoxt.imp.runtime.services.StrategoObserver.invoke(StrategoObserver.java:614) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:695) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:686) at org.strategoxt.imp.runtime.services.views.properties.PropertiesService.getProperties(PropertiesService.java:90) at org.strategoxt.imp.runtime.editor.StrategoTermSelection.getFirstElement(StrategoTermSelection.java:68) at org.strategoxt.imp.runtime.editor.SpoofaxEditor$3.run(SpoofaxEditor.java:109) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53) Internal error evaluating strategy editor-properties editor_properties_0_0 get_all_editor_properties_1_2 target_prop_1_0 pp_ast_1_0 z_112972 prettyprint_Start_0_0 pp_one_Z_1_0 pp_one_1_0 m_112965 java.lang.ArrayIndexOutOfBoundsException: -3 at org.spoofax.interpreter.core.StackTracer.push(StackTracer.java:39) at org.strategoxt.stratego_lib.set_config_0_0.invoke(set_config_0_0.java:21) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:816) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:807) at org.strategoxt.imp.runtime.services.StrategoObserver.invoke(StrategoObserver.java:614) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:695) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:686) at org.strategoxt.imp.runtime.services.views.properties.PropertiesService.getProperties(PropertiesService.java:90) at org.strategoxt.imp.runtime.editor.StrategoTermSelection.getFirstElement(StrategoTermSelection.java:68) at org.strategoxt.imp.runtime.editor.SpoofaxEditor$3.run(SpoofaxEditor.java:109) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53) Internal error evaluating strategy editor-properties editor_properties_0_0 get_all_editor_properties_1_2 target_prop_1_0 pp_ast_1_0 z_112972 prettyprint_Start_0_0 pp_one_Z_1_0 pp_one_1_0 m_112965 pp_V_list_1_1 map_1_0 pp_one_V_1_0 pp_one_1_0 m_112965 pp_one_Z_1_0 pp_one_1_0 m_112965 pp_one_Z_1_0 pp_one_1_0 m_112965 pp_one_Z_1_0 pp_one_1_0 java.lang.ArrayIndexOutOfBoundsException: -5 at org.spoofax.interpreter.core.StackTracer.push(StackTracer.java:39) at org.strategoxt.stratego_lib.set_config_0_0.invoke(set_config_0_0.java:21) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:816) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:807) at org.strategoxt.imp.runtime.services.StrategoObserver.invoke(StrategoObserver.java:614) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:695) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:686) at org.strategoxt.imp.runtime.services.views.properties.PropertiesService.getProperties(PropertiesService.java:90) at org.strategoxt.imp.runtime.editor.StrategoTermSelection.getFirstElement(StrategoTermSelection.java:68) at org.strategoxt.imp.runtime.editor.SpoofaxEditor$3.run(SpoofaxEditor.java:109) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53) Internal error evaluating strategy editor-properties editor_properties_0_0 get_all_editor_properties_1_2 target_prop_1_0 pp_ast_1_0 z_112972 prettyprint_Start_0_0 pp_one_Z_1_0 pp_one_1_0 m_112965 pp_V_list_1_1 map_1_0 pp_one_V_1_0 pp_one_1_0 m_112965 pp_one_Z_1_0 pp_one_1_0 m_112965 pp_one_Z_1_0 java.lang.ArrayIndexOutOfBoundsException: -2 at org.spoofax.interpreter.core.StackTracer.push(StackTracer.java:39) at org.strategoxt.stratego_lib.set_config_0_0.invoke(set_config_0_0.java:21) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:816) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:807) at org.strategoxt.imp.runtime.services.StrategoObserver.invoke(StrategoObserver.java:614) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:695) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:686) at org.strategoxt.imp.runtime.services.views.properties.PropertiesService.getProperties(PropertiesService.java:90) at org.strategoxt.imp.runtime.editor.StrategoTermSelection.getFirstElement(StrategoTermSelection.java:68) at org.strategoxt.imp.runtime.editor.SpoofaxEditor$3.run(SpoofaxEditor.java:109) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53) Internal error evaluating strategy editor-properties term_at_position_0_1 term_at_position_0_1 position_of_term_1_0 position_of_term_1_1 position_of_term_1_0 position_of_term_1_1 java.lang.ArrayIndexOutOfBoundsException: -1 at org.spoofax.interpreter.core.StackTracer.push(StackTracer.java:39) at org.strategoxt.stratego_lib.set_config_0_0.invoke(set_config_0_0.java:21) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:816) at org.strategoxt.imp.runtime.services.StrategoObserver.configureRuntime(StrategoObserver.java:807) at org.strategoxt.imp.runtime.services.StrategoObserver.invoke(StrategoObserver.java:614) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:695) at org.strategoxt.imp.runtime.services.StrategoObserver.invokeSilent(StrategoObserver.java:686) at org.strategoxt.imp.runtime.services.views.properties.PropertiesService.getProperties(PropertiesService.java:90) at org.strategoxt.imp.runtime.editor.StrategoTermSelection.getFirstElement(StrategoTermSelection.java:68) at org.strategoxt.imp.runtime.editor.SpoofaxEditor$3.run(SpoofaxEditor.java:109) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
Thinking about these stracktraces a little bit more, maybe this is somehow caused by concurrent use of the
StrategoObserver
, in a way that is not supported? It looks to me like multiple threads are working with the sameStrackTracer
instances, screwing up the stack and causing the index to go negative.
I did some debugging and it indeed seems to be a concurrency issue.
The problem occurs when you’re invoking a Strategy like this, but without first obtaining the reentrant lock of the observer:
position_of_term_1_0.instance.invoke(context, ast, testOrigin);
set_config_0_0.instance.invoke(context, programName);
Both the outline and the properties view rely on methods like
StrategoTermPath.getTermPathWithOrigin(...)
which invoke strategies in this way, hence the errors.I think what makes most sense is if we obtain the lock right before we invoke a strategy in such a way, and release it right afterwards. In other words, we should update methods like
StrategoTermPath.getTermPathWithOrigin(...)
andStrategoTextChangeCalculator.getTextReplacement(...)
. Any objections?This issue is indeed related to https://yellowgrass.org/issue/Spoofax/757
If it doesn’t cause any deadlock issues, that would be the fix for now. A proper fix would allow concurrent Stratego use, but that requires architectural changes, so that’s for another time.
Ok I consider this fixed: https://github.com/metaborg/spoofax/commit/eea1a3451daa15ac6b82770b43a92793110ca788
This interface change broke SPT, could you apply the changes to SPT’s Java files as well?
fixed https://github.com/metaborg/spt/commit/0411db5999bcf0faff1b6bdda709ad26e1d21af6
Thanks!
Log in to post comments