NPE in Extension Send

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

mdprasadeng
Posts: 9
Joined: 28 Apr 2020, 14:40

NPE in Extension Send

Postby mdprasadeng » 06 Aug 2021, 12:04

Hello,

We are seeing the following exception sometimes
java.lang.NullPointerException
at com.smartfoxserver.v2.api.SFSApi.sendExtensionResponse(SFSApi.java:1540)
at com.smartfoxserver.v2.extensions.BaseSFSExtension.send(BaseSFSExtension.java:487)

Can someone help us? Do we need to check something before calling send to make sure this doesn't happen.


Regards,
Durga
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPE in Extension Send

Postby Lapo » 06 Aug 2021, 13:39

Hi,
can you show the code that seems to trigger this error?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
mdprasadeng
Posts: 9
Joined: 28 Apr 2020, 14:40

Re: NPE in Extension Send

Postby mdprasadeng » 06 Aug 2021, 17:53

Hi Lapo,

The calling code is pretty basic

Code: Select all

public void sendToPlayer(
      GameOutbox.Cmds cmd, DiffResponse diffResponse, Game originalGame, Player player) {
    if (player.isBot()) return;
    User user = extension.getApi().getUserById(player.getSfsUserId());
    ISFSObject params = diffResponse.toSFSFor(originalGame, player);
    log(cmd, params, player.getId());
    extension.send(cmd.getCmd(), params, user, false);
  }
 


Can you share the line which is causing the NPE may be we can check what variable is null

Regards,
Durga.
mdprasadeng
Posts: 9
Joined: 28 Apr 2020, 14:40

Re: NPE in Extension Send

Postby mdprasadeng » 07 Aug 2021, 12:05

Hi Lapo,

Any update on this?

Right now we kill the gameroom whenever such exception occurs. Can we know why this is happening and how to recover from it if possible.

Regards,
Durga
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPE in Extension Send

Postby Lapo » 07 Aug 2021, 15:51

It may be that the user you're passing is null?
The line number doesn't correspond to anything significant in the current code base. What version of SFS2X are you using?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
mdprasadeng
Posts: 9
Joined: 28 Apr 2020, 14:40

Re: NPE in Extension Send

Postby mdprasadeng » 07 Aug 2021, 16:59

Hi Lapo, We are using 2.17.0.
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NPE in Extension Send

Postby Lapo » 07 Aug 2021, 20:24

An easy solution would just be to make sure you're not passing null parameters to the send() method.
We'll make sure to add these checks ourselves in the API for the next release. In particular I am referring to the User object.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 69 guests