Skip to content

fix: guard several edge cases that crash at runtime - #711

Open
yyqdbngt wants to merge 1 commit into
apache:masterfrom
yyqdbngt:fix/edge-case-defensive-checks
Open

fix: guard several edge cases that crash at runtime#711
yyqdbngt wants to merge 1 commit into
apache:masterfrom
yyqdbngt:fix/edge-case-defensive-checks

Conversation

@yyqdbngt

Copy link
Copy Markdown

Motivation

Four defensive fixes for runtime crashes found by code review:

  1. TopicServiceImpl.sendTopicMessageRequest — when a topic has no broker route, topicConfigInfos.get(0) threw IndexOutOfBoundsException. Now a clear ServiceException is thrown instead.

  2. DashboardCollectTask.collectBrokerkvTable.getTable().get("getTotalTps") could be null or blank, causing a NullPointerException or a divide-by-zero when the blank value splits into an empty array. The broker is now skipped when there is no TPS data.

  3. DashboardCollectServiceImpl.jsonDataFile2map — an empty or corrupt dashboard data file makes JSONObject.parse return null, so json.entrySet() threw NullPointerException. An empty map is returned instead.

  4. FileUserStrategy.FileBasedUserInfoStore.load — a non-numeric role in users.properties threw NumberFormatException outside of any try/catch, aborting application startup. It is now treated as a normal user (role 0) with a warning logged.

Verification

mvn compiler:compile passes (BUILD SUCCESS).

Diff

4 files changed, +21 / -3.

- TopicServiceImpl: sending a message to a topic without any broker route
  threw IndexOutOfBoundsException on topicConfigInfos.get(0); throw a
  ServiceException with a clear message instead
- DashboardCollectTask: kvTable.get("getTotalTps") could be null or blank,
  causing NPE or a divide-by-zero on the empty split result; skip the
  broker in that case
- DashboardCollectServiceImpl: an empty/corrupt dashboard data file makes
  JSONObject.parse return null and json.entrySet() NPE; return an empty
  map instead
- FileUserStrategy: a non-numeric role in users.properties threw
  NumberFormatException outside any try/catch and aborted startup; treat
  it as a normal user (role 0) and log a warning
@yyqdbngt
yyqdbngt force-pushed the fix/edge-case-defensive-checks branch from a360b58 to 5dbf47b Compare July 31, 2026 15:34
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.

1 participant