Skip to content

Enable null to remove server_message#330

Open
jimmyhong94 wants to merge 1 commit intoP0nk:masterfrom
jimmyhong94:remove_server_message
Open

Enable null to remove server_message#330
jimmyhong94 wants to merge 1 commit intoP0nk:masterfrom
jimmyhong94:remove_server_message

Conversation

@jimmyhong94
Copy link

Description

An empty server message in config.yaml would cause a NullPointerException when logging in (after selecting your character to play) since the server message would be null while the code expects a string.

This change prevents an empty server_message in config.yaml causing the exception.

Error found when trying an empty server_message:

java.lang.NullPointerException: Cannot invoke "String.getBytes(java.nio.charset.Charset)" because "value" is null
        at net.packet.ByteBufOutPacket.writeString(ByteBufOutPacket.java:74)
        at tools.PacketCreator.serverMessage(PacketCreator.java:1281)
        at tools.PacketCreator.serverMessage(PacketCreator.java:1220)
        at net.server.channel.Channel.addPlayer(Channel.java:271)
        at net.server.channel.handlers.PlayerLoggedinHandler.handlePacket(PlayerLoggedinHandler.java:228)
        at client.Client.channelRead(Client.java:221)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
        at ...

Error is now removed and server message on top of the view is gone when the config has a null server message.

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have tested my changes
  • I have added unit tests that prove my changes work

Screenshots

Server message removed when null / does not run into NullPointerException:
Null, No Error, Server Message Gone

Server message showing still with my changes (intended):
Server Message Working On Changes

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