The GitHub Actions job "CodeQL" on 
commons-scxml.git/SCXML-290-initGlobalsScript-visibility has failed.
Run started by GitHub user akashchamp (triggered by akashchamp).

Head commit for run:
9aefbf541600ae5278f39b13dd894fa2f37e8f2f / Akash Kumar 
<[email protected]>
[SCXML-290] Make JSEvaluator.initGlobalsScript volatile

JSEvaluator#initGlobalsScript is a private static String that caches the
contents of the init_global.js classpath resource. It is written exactly
once, inside the per-instance synchronized initEngine() method, but is
read without any synchronization from getScriptContext() (and by every
other JSEvaluator instance's initEngine() null-check).

Because initEngine() synchronizes on the individual JSEvaluator instance
(this), and separate instances are commonly constructed concurrently
(one per SCXML instance), the write to the static field and a read of it
on another instance do not share a common monitor. The JMM therefore does
not guarantee that a thread will observe the script content published by
another thread's initEngine() call; it may observe a stale or null value.

Marking the field volatile establishes the required happens-before edge
between any write and any subsequent read, independent of which instance
or monitor performed the write, fixing the visibility gap directly at its
source.

Also adds a JSEvaluatorTest that constructs and evaluates many JSEvaluator
instances concurrently, exercising the previously-racy initialization path
under real thread contention.

Generated-by: Claude Sonnet 5 -- 
https://www.apache.org/legal/generative-tooling.html

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Report URL: https://github.com/apache/commons-scxml/actions/runs/36175493137

With regards,
GitHub Actions via GitBox

Reply via email to