Title: NullPointerException in HandlerManager when enabling Python addon on second instrument · Issue #36 · BookmapAPI/python-api · GitHub
Open Graph Title: NullPointerException in HandlerManager when enabling Python addon on second instrument · Issue #36 · BookmapAPI/python-api
X Title: NullPointerException in HandlerManager when enabling Python addon on second instrument · Issue #36 · BookmapAPI/python-api
Description: NullPointerException in HandlerManager when enabling Python addon on second instrument Environment Bookmap version: 7.6.0 build 30 Bookmap embedded Python: 3.9 (miniforge bm39 env) OS: Windows 11 (WSL Ubuntu-24.04 used to host the addon ...
Open Graph Description: NullPointerException in HandlerManager when enabling Python addon on second instrument Environment Bookmap version: 7.6.0 build 30 Bookmap embedded Python: 3.9 (miniforge bm39 env) OS: Windows 11 (...
X Description: NullPointerException in HandlerManager when enabling Python addon on second instrument Environment Bookmap version: 7.6.0 build 30 Bookmap embedded Python: 3.9 (miniforge bm39 env) OS: Windows 11 (...
Opengraph URL: https://github.com/BookmapAPI/python-api/issues/36
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NullPointerException in HandlerManager when enabling Python addon on second instrument","articleBody":"# NullPointerException in HandlerManager when enabling Python addon on second instrument\n\n## Environment\n\n- **Bookmap version:** 7.6.0 build 30\n- **Bookmap embedded Python:** 3.9 (miniforge `bm39` env)\n- **OS:** Windows 11 (WSL Ubuntu-24.04 used to host the addon source)\n- **Data provider:** Rithmic Paper\n- **Instruments tested:** NQM6.CME@RITHMIC, ESM6.CME@RITHMIC\n- **Strategy type:** Simplified L1 Python addon\n- **Loader:** `runpy.run_path(...)` from Bookmap's Python editor\n\n## Summary\n\nA Python addon that subscribes to multiple instruments via `INSTRUMENT_ALIASES`\ncrashes Bookmap with `java.lang.NullPointerException` in\n`HandlerManager.handle()` immediately after the `subscribe` handler\nfires for the second instrument. The crash happens regardless of which\ninstrument is enabled first (NQ then ES, or ES then NQ), and regardless\nof the Python-side state. Single-instrument operation works perfectly.\n\n## Reproduction steps\n\n1. Create a Python addon (full code below) that calls `bm.create_addon`,\n adds trades + depth + on_interval handlers, and starts with\n `bm.start_addon(addon, subscribe_handler, unsubscribe_handler)`.\n2. Load the script in Bookmap via the Python editor:\n ```python\n import runpy\n runpy.run_path(r'\u003cpath_to_script>', run_name='__main__')\n ```\n3. Enable the addon for the **first** instrument (e.g. NQM6.CME@RITHMIC).\n Observe: subscribe handler fires correctly, addon starts processing.\n `snapshot.json` is written every 100ms with valid data. ✅\n4. Enable the addon for the **second** instrument (e.g. ESM6.CME@RITHMIC),\n without disabling the first. Observe:\n - Python's `subscribe` handler IS called for the second instrument\n - `STATE` dict reaches size 2\n - **~2ms later**, Bookmap throws `NullPointerException` and unloads\n the addon. ❌\n\nThe same crash happens in the reverse order (ES first, then NQ).\n\n## Stack trace\n\n```\njava.lang.NullPointerException: Cannot invoke\n\"com.bookmap.api.rpc.server.handlers.HandlerManager.handle(com.bookmap.api.rpc.server.data.utils.AbstractEvent)\"\nbecause \"this.handlerManager\" is null\n\tat com.bookmap.api.rpc.server.EventLoop.lambda$new$0(EventLoop.java:27)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n\tat java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n\tat java.base/java.lang.Thread.run(Unknown Source)\n```\n\nAfter the NPE, Bookmap unloads the addon (`Unloading strategy/indicator\n... bm_producer.jar`), the Python `unsubscribe_instrument` handler is\ncalled for the first instrument, and the addon process exits. Settings\nget persisted with `disabling for ESM6.CME@RITHMIC` flags so the\n`Strategy settings were saved before it was loaded last time` message\nappears on the next load.\n\n## Relevant Bookmap log excerpt\n\n```\n20260428 22:11:05.581 (AWT-EventQueue-1) Stratgies dialog: com.bookmap.api.rpc.server.addon.bm_producer true\n20260428 22:11:05.581 (AWT-EventQueue-1) Enabled for NQM6.CME@RITHMIC true - started (Simplified L1)\n20260428 22:11:05.613 (AWT-EventQueue-1) BrApi(...): Add-on \"bm_producer\" - Became available for broadcasts as a consumer.\n20260428 22:11:05.614 [PYTHON-CLIENT] [bm_producer] subscribe alias=NQM6.CME@RITHMIC ... pips=0.25 size_mult=1.0\n20260428 22:11:05.614 [PYTHON-CLIENT] [bm_producer] registered short=NQ trades+depth subscribed; STATE size=2\n20260428 22:11:05.614 [RPC-SERVER] Received finish initialization message for NQM6.CME@RITHMIC\n20260428 22:11:05.616 (AWT-EventQueue-1) Enabled for NQM6.CME@RITHMIC true - complete (Simplified L1)\n20260428 22:11:05.618 ERROR: (Global Exception Handler) Intercepted exception from strategy\njava.lang.NullPointerException: Cannot invoke \"com.bookmap.api.rpc.server.handlers.HandlerManager.handle(...)\" because \"this.handlerManager\" is null\n at com.bookmap.api.rpc.server.EventLoop.lambda$new$0(EventLoop.java:27)\n ...\n20260428 22:11:05.624 (AWT-EventQueue-1) Unloading strategy/indicator C:\\Bookmap\\Python\\build\\bm_producer.jar com.bookmap.api.rpc.server.addon.bm_producer\n```\n\n(In this excerpt, ES had been enabled first at 22:09:53 and worked\ncorrectly for ~72 seconds. NQ was enabled at 22:11:05; the NPE\noccurred at 22:11:05.618 — about 2ms after the Python-side `subscribe`\nhandler completed for NQ.)\n\n## Minimal repro script\n\n```python\n\"\"\"Minimal reproduction of NPE when enabling addon on second instrument.\"\"\"\nimport bookmap as bm\nimport threading\nfrom datetime import datetime, timezone\n\ndef stamp():\n return datetime.now(timezone.utc).isoformat(timespec=\"microseconds\")\n\ndef log(msg):\n print(\"[repro] [\" + stamp() + \"] \" + msg, flush=True)\n\nSTATE = {}\n\ndef handle_subscribe_instrument(addon, alias, full_name, is_crypto, pips,\n size_multiplier, instrument_multiplier,\n supported_features):\n log(\"subscribe alias=\" + str(alias) + \" (STATE size before=\" + str(len(STATE)) + \")\")\n STATE[alias] = {\"order_book\": bm.create_order_book()}\n bm.subscribe_to_trades(addon, alias, len(STATE))\n bm.subscribe_to_depth(addon, alias, len(STATE) + 100)\n log(\" subscribed; STATE size=\" + str(len(STATE)))\n\ndef handle_unsubscribe_instrument(addon, alias):\n log(\"unsubscribe alias=\" + str(alias))\n STATE.pop(alias, None)\n\ndef handle_trades(addon, alias, price, size, is_otc, is_bid,\n is_execution_start, is_execution_end,\n aggressor_order_id, passive_order_id):\n pass # no-op\n\ndef handle_depth(addon, alias, is_bid, price, size):\n state = STATE.get(alias)\n if state is not None:\n bm.on_depth(state[\"order_book\"], is_bid, price, size)\n\ndef on_interval(addon, alias):\n pass # no-op\n\nif __name__ == \"__main__\":\n log(\"STARTUP, thread=\" + threading.current_thread().name)\n addon = bm.create_addon()\n bm.add_trades_handler(addon, handle_trades)\n bm.add_depth_handler(addon, handle_depth)\n bm.add_on_interval_handler(addon, on_interval)\n bm.start_addon(addon, handle_subscribe_instrument, handle_unsubscribe_instrument)\n log(\"Addon started, blocking...\")\n bm.wait_until_addon_is_turned_off(addon)\n log(\"Addon stopped.\")\n```\n\nTo reproduce:\n1. Save as `repro.py`.\n2. Load in Bookmap via `runpy.run_path(r'\u003cpath>', run_name='__main__')`.\n3. Enable for any single instrument — works fine.\n4. Enable for a second instrument (without disabling the first) — NPE.\n\n## What I expected\n\nPer the official `start_addon` documentation:\n> `handle_subscribe_instrument` is a function that you should define.\n> It will be called **each time you enable the addon in Bookmap for a\n> certain instrument**.\n\nThis wording suggests one Python addon should handle multiple\ninstruments by receiving multiple `subscribe` calls (one per\ninstrument). The official examples (`mbo_test.py`, `cvd_addon.py`,\n`liquidity_tracker.py`, `simple_market_maker.py`) all use this pattern\nwith `alias_to_*` dicts, implying multi-instrument is the intended\ndesign.\n\n## What actually happens\n\nThe `subscribe` handler fires correctly for the second instrument, but\nBookmap's internal `EventLoop` then tries to dispatch an event to a\n`HandlerManager` that is `null`. This suggests the second-instrument\ninitialization path has a race condition or missing initialization on\nthe Java side.\n\n## Workaround currently in use\n\nI've added a guard in my Python addon that refuses any `subscribe` call\nbeyond the first. This restricts the addon to one instrument per\nsession. The user must disable the addon entirely before switching to\na different instrument. This works but defeats the whole point of\nmulti-instrument addons.\n\n```python\ndef handle_subscribe_instrument(addon, alias, ...):\n if len(STATE) >= 1:\n log(\"REFUSED: already subscribed to \" + str(list(STATE.keys())[0]))\n return\n # ... normal subscribe path ...\n```\n\n## Questions for the team\n\n1. Is there a known issue with multi-instrument Simplified L1 Python\n addons in Bookmap 7.6.0?\n2. Should the Python API support multi-instrument in the same addon,\n or is it expected behavior that each instrument requires a separate\n addon load?\n3. If multi-instrument is supported, is there an initialization order\n or method I'm missing in the bootstrap?\n4. If NOT supported, what's the recommended pattern for an addon that\n needs to read data from multiple instruments simultaneously (e.g.\n to compute cross-instrument correlations)?\n\nHappy to provide more logs, test other configurations, or run a debug\nbuild if helpful.\n\nThanks!\n","author":{"url":"https://github.com/michaelalvarezm","@type":"Person","name":"michaelalvarezm"},"datePublished":"2026-04-28T22:42:27Z","url":"https://github.com/BookmapAPI/python-api/issues/36"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:852f7cd0-c89b-0544-d9d5-9f6ce3f8cd5b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E358:27A9B8:1A48308:228AA18:6B040B48 |
| html-safe-nonce | d13b394cc6d9a292c190e86adf8eb372136e43d014446bc7de96833e1522473b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMzU4OjI3QTlCODoxQTQ4MzA4OjIyOEFBMTg6NkIwNDBCNDgiLCJ2aXNpdG9yX2lkIjoiMzc0MzE5OTAyOTczNjI0NjA4OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3400be5dadb6f6a69f97ef433d71d4732797337d95577af1cbcbbbb012eaaa39 |
| hovercard-subject-tag | issue:4346698475 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/BookmapAPI/python-api/36/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d816c9fe14e90b99455e1b091e86e6f7966e7c8c09f46acc09df7b65586639f7/BookmapAPI/python-api/issues/36 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d816c9fe14e90b99455e1b091e86e6f7966e7c8c09f46acc09df7b65586639f7/BookmapAPI/python-api/issues/36 |
| og:image:alt | NullPointerException in HandlerManager when enabling Python addon on second instrument Environment Bookmap version: 7.6.0 build 30 Bookmap embedded Python: 3.9 (miniforge bm39 env) OS: Windows 11 (... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | michaelalvarezm |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/BookmapAPI/python-api git https://github.com/BookmapAPI/python-api.git |
| octolytics-dimension-user_id | 25076219 |
| octolytics-dimension-user_login | BookmapAPI |
| octolytics-dimension-repository_id | 536529076 |
| octolytics-dimension-repository_nwo | BookmapAPI/python-api |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 536529076 |
| octolytics-dimension-repository_network_root_nwo | BookmapAPI/python-api |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width