Sean-Walker0 opened a new pull request, #7334: URL: https://github.com/apache/shenyu/pull/7334
<!-- Describe your PR here; e.g. Fixes #issueNo --> Found by code audit (no existing issue — happy to file one if maintainers prefer). `ClusterSelectMasterServiceJdbcImpl#getMasterUrl` dereferences `clusterMasterMapper.selectById(MASTER_ID)` with no null check (`master.getContextPath()`). The master row is only inserted by the first successful `selectMaster` (`selectMaster(host, port, contextPath)` → `clusterMasterMapper.insert`), so a **slave** node serving a `RUNNING_MODE` websocket request before any master persisted its row throws `NullPointerException` during response assembly — `WebsocketCollector#onMessage` calls `getMasterUrl()` on every such request and then does `masterUrl.replace(...).concat(...)`, which also requires a non-null value. The sibling method directly above, `getMaster()`, guards exactly this lookup (`Objects.isNull(masterDO) ? new ClusterMasterDTO() : ...`) — proving the missing row is an anticipated state, not an error. <!-- Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request. --> Make sure that: - [x] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [x] You submit test cases (unit or integration tests) that back your changes. - [x] Your local test passed `./mvnw test -pl shenyu-admin -am and ./mvnw checkstyle:check -pl shenyu-admin` (module-scoped; full build left to CI). ### Modifications - Mirror `getMaster()`'s guard: when the row is absent, return `StringUtils.EMPTY`, which the only caller already tolerates (its replace/concat chain just produces an empty master URL field). ### Verifying this change - New `testGetMasterUrlShouldNotThrowWhenMasterRowIsAbsent` mocks the mapper to return null and asserts `getMasterUrl()` returns an empty string. It fails on current master with `NullPointerException: Cannot invoke "ClusterMasterDO.getContextPath()" because "master" is null` and passes with this change. - Full `shenyu-admin` module suite green (502 test classes); checkstyle green. ### Notes - Behavior change: `RUNNING_MODE` responses on a slave node before the first master election no longer fail with a 500/NPE — they carry an empty `masterUrl` until a master is recorded. - Orthogonal to open PRs: no open PR touches `ClusterSelectMasterServiceJdbcImpl` (checked against the file lists of all 185 open PRs). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
