Skip to content

ChatBox treats username 'server' as a system message, and clearChat can NPE after dispose #9

Description

@CanReader

Two small things in ChatBox.addText:

if(username.equals("server") || color.contains("null")){
    adapter.addItem(Localization.getLocalizedString(message));
} else
    adapter.addItem(new UserMessageString(username, message, color));
  1. It decides a message is a system message by checking username.equals("server"). But "server" is a perfectly valid username (the validator allows [a-zA-Z0-9_]{3,15}). So a real player who registers the username "server" has every chat line they send run through Localization.getLocalizedString(message) and rendered as a system message instead of their actual text. Same for color.contains("null") matching more broadly than intended. System messages should be tagged by something the client controls, not by a magic username string.

  2. clearChat() doesn't null-check activity the way addText does:

public void clearChat() {
    ((ChatListAdapter) Objects.requireNonNull(chatList.getAdapter())).clear();
    InputMethodManager inputMan = activity.getSystemService(InputMethodManager.class);   // activity may be null after dispose
    ...
}

addText guards with if (activity == null) return; because a late socket event can arrive after teardown. clearChat() is reachable the same way (CLEAR_CHAT socket event) but has no guard, so a CLEAR_CHAT arriving after the ChatBox is disposed NPEs on activity.

File: android/src/com/focus/kingdom/ui/widget/ChatBox.java, addText line ~104-121 and clearChat line ~123-133.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions