[Bug]: Add-on JavaScript context not cleaned up when removing an add-on.
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- java, javascript
Research direction
Start from the stack in AddOnLibrary.java (callMTSFunction / onInit eval) and the remove-library path under File > Add On Libraries. Trace how addon JS namespaces and Graal/polyglot contexts are created versus torn down so leftover namespaces (data.listNamespaces("addon:")) and const redefinition errors go away. Done when removing a library clears its context and re-adding the same add-on works without ParserException.
Written by the indexing model from the issue text.
Description
Describe the Bug
When an add-on is installed in a campaign, a new context is created within which the add-on's JavaScript can executed. When the add-on is removed, this context remains. Adding the same add-on again can then cause errors (e.g.,, if the same variables gets defined) or fail for logical reasons if old state is used.
To Reproduce
- Download this example add-on: collision-example.mtlib
- Drag the add-on into a blank campaign.
- Open File > Add On Libraries ..., select the add-on and click Remove Library.
- Notice that typing
[r: data.listNamespaces("addon:")]in the chat window results in the add-on namespace still be visible.
- Notice that typing
- Drag the add-on into the campaign again.
- Notice the error that gets presented.
The key detail in the attached add-on is that it evals this line during onInit:
const namespace = 'com.kwvanderlinde.collision';
The display of the error is not 100% consistent, so you may have to repeat steps (3) & (4) a couple times.
Expected Behaviour
When an add-on is removed, all of its state is also removed (namespace and associated context). It should be possible to add the add-on again to the same campaign without issue (unless the add-on itself is at fault for doing something very bad).
Screenshots
No response
MapTool Info
1.18.6
Desktop
Linux Mint 22.1
Additional Context
Here is the error:
java.util.concurrent.CompletionException: net.rptools.parser.ParserException: com.oracle.truffle.polyglot.PolyglotEngineException error executing expression js.evalURI("com.kwvanderlinde.collision", "lib://com.kwvanderlinde.collision/example.js").
at net.rptools.maptool.model.library.addon.AddOnLibrary.lambda$callMTSFunction$15(AddOnLibrary.java:672)
at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:63)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.WaitDispatchSupport$2.run(Unknown Source)
at java.desktop/java.awt.WaitDispatchSupport$4.run(Unknown Source)
at java.desktop/java.awt.WaitDispatchSupport$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.desktop/java.awt.WaitDispatchSupport.enter(Unknown Source)
at java.desktop/java.awt.Dialog.show(Unknown Source)
at java.desktop/javax.swing.JOptionPane.showOptionDialog(Unknown Source)
at java.desktop/javax.swing.JOptionPane.showMessageDialog(Unknown Source)
at java.desktop/javax.swing.JOptionPane.showMessageDialog(Unknown Source)
at net.rptools.maptool.client.MapTool.showMessage(MapTool.java:257)
at net.rptools.maptool.client.MapTool.showInformation(MapTool.java:380)
at net.rptools.maptool.client.MapTool.showInformation(MapTool.java:363)
at net.rptools.maptool.client.TransferableHelper.lambda$importData$1(TransferableHelper.java:566)
at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.desktop/java.awt.EventQueue$4.run(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source)
at net.rptools.maptool.client.swing.MapToolEventQueue.dispatchEvent(MapToolEventQueue.java:63)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)
Caused by: net.rptools.parser.ParserException: com.oracle.truffle.polyglot.PolyglotEngineException error executing expression js.evalURI("com.kwvanderlinde.collision", "lib://com.kwvanderlinde.collision/example.js").
at net.rptools.maptool.client.MapToolLineParser.parseExpression(MapToolLineParser.java:1124)
at net.rptools.maptool.client.MapToolLineParser.parseLine(MapToolLineParser.java:857)
at net.rptools.maptool.client.MapToolLineParser.runMacroBlock(MapToolLineParser.java:1456)
at net.rptools.maptool.client.MapToolLineParser.runMacro(MapToolLineParser.java:1380)
at net.rptools.maptool.client.MapToolLineParser.runMacro(MapToolLineParser.java:1177)
at net.rptools.maptool.model.library.addon.AddOnLibrary.lambda$callMTSFunction$15(AddOnLibrary.java:670)
... 38 more
- Dominant language
- Java
- Stars
- 927
- Forks
- 286
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 94
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from RPTools/maptool
-
[Bug]: An initiative list with no current entry logs an error on every changePossibly taken @dwizard0 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
[Maintenance]: Migrate gradle dependency submission to modern alternativePossibly taken @VelpulaGangavardhan claimed this 18 days ago. Opencode-maintenance
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
RPTools/maptool#6156 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
code-maintenance
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
Similar issues
-
Cleanup: restore the interrupt flag in AiFailureAnalyzerPossibly taken @Rishankgupta08 claimed this today. Opengood first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
seleniumboot/selenium-boot#258 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
johanhaleby/occurrent#1505 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
FasterXML/jackson-databind#6443 ·
Maintainers usually reply within 1 day
-
Docs: 2 broken linksOpen
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Maintainers usually reply within 1 day