Page 1 of 1

Admin zone error on TraceMessageEvtHandler.java:45

Posted: 10 Dec 2018, 12:11
by imantexas
Hello everyone

I'm pretty new here and I'm enjoying using Smartfox engine, it's fantastic,
I got this error every time some one calls a specific function, the function itself works fine and it's pretty much like other functions that I have:

Code: Select all

10 Dec 2018 | 15:30:31,642 | WARN  | SFSWorker:Ext:2 | entities.managers.SFSExtensionManager |     | java.lang.NullPointerException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: Error during event handling: java.lang.NullPointerException, Listener: { Ext: Admin, Type: JAVA, Lev: ZONE, { Zone: --=={{{ AdminZone }}}==-- }, {} }
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.admin.handlers.events.TraceMessageEvtHandler.handleServerEvent(TraceMessageEvtHandler.java:45)
com.smartfoxserver.v2.extensions.SFSExtension.handleServerEvent(SFSExtension.java:259)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:768)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchZoneLevelEvent(SFSExtensionManager.java:689)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:1023)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:66)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


since it happens in Admin zone I don't know what to do to get rid of it!
thanks for helping

Re: Admin zone error on TraceMessageEvtHandler.java:45

Posted: 10 Dec 2018, 14:09
by Lapo
Hi,
what version of SFS2X are you using?
Also, can you explain what is this "specific function" you're using and that triggers the issue?

Maybe show us the relevant code, if it's not too long.

Thanks

Re: Admin zone error on TraceMessageEvtHandler.java:45

Posted: 11 Dec 2018, 06:44
by imantexas
Hi Lapo, thanks for quick reply,

I'm using ver. 2.13.1 and sure, here is the code:

Code: Select all

   trace("done getting cards!");

   // give the selected cards to player
        for (int i = 0; i < cards.size(); i++)
        {
            ISFSObject obj = cards.getSFSObject(i);
            GivePlayerCards(_userID, obj.getInt("id"), obj.getInt("count"));
        }

and:

Code: Select all

    private void GivePlayerCards(int _userID, int _itemID, int _count) throws SQLException, NoSuchAlgorithmException
    {
        sql = connection.prepareStatement("SELECT id FROM user_item_unlocks WHERE user_id=? AND item_id = ? AND deleted IS NULL");
        sql.setInt(1, _userID);
        sql.setInt(2, _itemID);
        result = sql.executeQuery();
        if (result.isBeforeFirst()) // player already unlocked this item so just increase the cards
        {
            result.next();
            sql = connection.prepareStatement("UPDATE user_item_unlocks SET cards = cards + ?, gained = gained + ? WHERE id=?");
            sql.setInt(1, _count);
            sql.setInt(2, _count);
            sql.setInt(3, result.getInt("id"));
            sql.executeUpdate();
        }
        else // unlock the item for player
        {
            sql = connection.prepareStatement("INSERT INTO user_item_unlocks (user_id, item_id, cards, created) VALUES(?, ?, ?, ?)");
            sql.setInt(1, _userID);
            sql.setInt(2, _itemID);
            sql.setInt(3, _count);
            sql.setString(4, Utility.GetTimeString(0));
            sql.executeUpdate();
        }
    }


I know it throws the exception here cause I can see the "done getting cards!" in the log before the error.
thanks

Re: Admin zone error on TraceMessageEvtHandler.java:45

Posted: 11 Dec 2018, 08:42
by Lapo
Hi,
I am not sure the code you have posted is the cause of the error.
The stack trace indicates that the NPE is thrown inside the AdminTool while handling a trace message. This means that the trigger of the error is caused by a call to the trace() method inside the Extension.

What I would expect is that a call to trace() is passing a null parameter and cause the issue.

Can you double check?

Re: Admin zone error on TraceMessageEvtHandler.java:45

Posted: 11 Dec 2018, 10:46
by imantexas
You are right Lapo, I had a line of code like this:

Code: Select all

trace("done getting cards! ----------------------------");


and for some reason trace() couldn't handle "--------------------------" part! I removed "-----------------" and the error is gone now.

oh wait now it throes this error:

Code: Select all

11 Dec 2018 | 14:21:25,428 | WARN  | SFSWorker:Ext:1 | entities.managers.SFSExtensionManager |     | java.lang.NullPointerException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: Error during event handling: java.lang.NullPointerException, Listener: { Ext: Admin, Type: JAVA, Lev: ZONE, { Zone: --=={{{ AdminZone }}}==-- }, {} }
+--- --- ---+
Stack Trace:
+--- --- ---+
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Re: Admin zone error on TraceMessageEvtHandler.java:45

Posted: 11 Dec 2018, 15:42
by Lapo
Are you really sure that's the cause?
I don't think a simple trace() like that can cause such error. Otherwise this would be a super common problem every time you try to log something, which it isn't.

Re: Admin zone error on TraceMessageEvtHandler.java:45

Posted: 13 Dec 2018, 15:19
by imantexas
I'm not sure but I changed that one line of code and the error message changed, so it should be!
I didn't find anything else yet i'll let you know,

cheers