Skip to content

Guard null in GlobalVariableStore lock/unlock#311

Open
NicoPiel wants to merge 1 commit into
OpenIntegrationEngine:mainfrom
NicoPiel:fix/globalvariablestore-npe
Open

Guard null in GlobalVariableStore lock/unlock#311
NicoPiel wants to merge 1 commit into
OpenIntegrationEngine:mainfrom
NicoPiel:fix/globalvariablestore-npe

Conversation

@NicoPiel
Copy link
Copy Markdown
Collaborator

@NicoPiel NicoPiel commented May 25, 2026

$gc()/$g() JS APIs call lock() on keys never registered via putSync(), causing NPE; throw IllegalArgumentException with clear message instead

@NicoPiel NicoPiel changed the title fix: guard null in GlobalVariableStore lock/unlock Guard null in GlobalVariableStore lock/unlock May 25, 2026
@NicoPiel NicoPiel requested review from a team, gibson9583, jonbartels, kayyagari, mgaffigan, pacmano1, ssrowe and tonygermano and removed request for a team May 25, 2026 21:20
$gc()/$g() JS APIs call lock() on keys never registered via putSync(), causing NPE; throw IllegalArgumentException with clear message instead

Signed-off-by: Nico Piel <nico.piel@hotmail.de>
@NicoPiel NicoPiel force-pushed the fix/globalvariablestore-npe branch from fa0fb42 to 2e0ff41 Compare May 25, 2026 21:21
@github-actions
Copy link
Copy Markdown

Test Results

  111 files  ±0    214 suites  ±0   6m 59s ⏱️ + 1m 9s
  654 tests ±0    654 ✅ ±0  0 💤 ±0  0 ❌ ±0 
1 308 runs  ±0  1 308 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 2e0ff41. ± Comparison against base commit 5423492.

@mgaffigan
Copy link
Copy Markdown
Contributor

How can this issue be reproduced?

@NicoPiel
Copy link
Copy Markdown
Collaborator Author

NicoPiel commented May 25, 2026

JavaScript transformer in any channel:

// Never called putSync("myKey", ...) first
globalMap.lock("myKey");   // → NPE

More realistic scenari: race condition or misconfigured channel:

// Channel A clears sync map or removes a key
globalMap.clearSync();  // or globalMap.removeSync("sharedKey")

// Channel B (running concurrently) tries to lock the now-missing key
globalMap.lock("sharedKey");  // → NPE

Will throw something like:

DETAILS:	Wrapped java.lang.NullPointerException: Cannot invoke "com.mirth.connect.server.util.SyncObject.getLock()" because the return value of "java.util.Map.get(Object)" is null
	at b3ce21c4-952b-47ff-88d6-8b5cdf19fcfe_JavaScript_Filter_Transformer_0:103 (doTransform)
	at b3ce21c4-952b-47ff-88d6-8b5cdf19fcfe_JavaScript_Filter_Transformer_0:125 (doScript)
	at b3ce21c4-952b-47ff-88d6-8b5cdf19fcfe_JavaScript_Filter_Transformer_0:127
	at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:235)
	at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:187)
	at com.mirth.connect.server.util.javascript.JavaScriptTask.call(JavaScriptTask.java:114)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.NullPointerException: Cannot invoke "com.mirth.connect.server.util.SyncObject.getLock()" because the return value of "java.util.Map.get(Object)" is null
	at com.mirth.connect.server.util.GlobalVariableStore.lock(GlobalVariableStore.java:72)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:138)
	at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:226)
	at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1692)
	at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1013)
	at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:109)
	at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:412)
	at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3578)
	at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:121)
	at com.mirth.connect.server.util.javascript.JavaScriptTask.executeScript(JavaScriptTask.java:151)
	at com.mirth.connect.server.transformers.JavaScriptFilterTransformer$FilterTransformerTask.doCall(JavaScriptFilterTransformer.java:224)
	... 6 more

Copy link
Copy Markdown
Contributor

@kryskool kryskool left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants