IDBManager and Null values

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

Moderators: Lapo, Bax

Kai
Posts: 17
Joined: 22 Oct 2009, 16:41

IDBManager and Null values

Postby Kai » 22 Dec 2010, 12:32

Hi,

I just had a particular issue where a mysql database table accepts null values for date time field. However, when attempting to return the record via executeQuery results in a java null pointer exception.

13:45:21,046 WARN [pool-1-thread-2] managers.SFSExtensionManager -
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: Error during event handling: java.lang.NullPointerException, Listener: { Ext: myext, Type: JAVA, Lev: ZONE, { Zone: myzone}, {} }
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.resultSet2object(DefaultSFSDataSerializer.java:388)
com.smartfoxserver.v2.protocol.serialization.DefaultSFSDataSerializer.resultSet2array(DefaultSFSDataSerializer.java:466)
com.smartfoxserver.v2.entities.data.SFSArray.newFromResultSet(SFSArray.java:108)
com.smartfoxserver.v2.db.SFSDBManager.executeQuery(SFSDBManager.java:152)
com.smartfoxserver.v2.db.SFSDBManager.executeQuery(SFSDBManager.java:121)
[My database calling executeQuery()]
[My UserJoinZoneEventHandler.handleServerEvent]
com.smartfoxserver.v2.extensions.SFSExtension.handleServerEvent(SFSExtension.java:242)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:779)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchZoneLevelEvent(SFSExtensionManager.java:704)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:897)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:64)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


I can get around this by ensuring that the field contains a really old date or something, but this does not look like something that was added on purpose.
User avatar
Lapo
Site Admin
Posts: 21645
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 23 Dec 2010, 15:12

You are right, fields are not expected to be null at the moment.
It's probably a necessary addition to avoid unexpected problems, thanks for reporting. We'll update it in the next release.
Lapo
--
gotoAndPlay()
...addicted to flash games
dingo
Posts: 97
Joined: 27 Jan 2009, 21:34

Postby dingo » 17 Mar 2011, 15:20

i just downloaded RC2a and I'm still getting the following error:
"Message: SFSObject requires a non-null value! If you need to add a null use the putNull() method."

I verified that I'm using the latest version of the library, did a clean&build of the jar, restarted the server but I still get the same error.
dingo
Posts: 97
Joined: 27 Jan 2009, 21:34

Postby dingo » 17 Mar 2011, 16:04

i should mention that I'm using it like this:

Code: Select all

mySfsObj.putUtfString("description", nullValue);
User avatar
Lapo
Site Admin
Posts: 21645
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 18 Mar 2011, 07:43

Which is not supported.
You need to use putNull("keyName").
Lapo

--

gotoAndPlay()

...addicted to flash games
dingo
Posts: 97
Joined: 27 Jan 2009, 21:34

Postby dingo » 18 Mar 2011, 11:18

ok, i get it, thanks.
FireSmartFox
Posts: 29
Joined: 28 Sep 2018, 19:47

Re: IDBManager and Null values

Postby FireSmartFox » 05 Apr 2019, 13:11

Did this change? It seems that not.
I found this out while debugging since suddenly a part of the application wsa not working. :shock:
User avatar
Lapo
Site Admin
Posts: 21645
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: IDBManager and Null values

Postby Lapo » 05 Apr 2019, 13:50

This is a very old thread. Can you describe what problems are you seeing exactly, and under which SFS2X version?
Maybe starting a new thread would be best.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
FireSmartFox
Posts: 29
Joined: 28 Sep 2018, 19:47

Re: IDBManager and Null values

Postby FireSmartFox » 05 Apr 2019, 14:01

It's exactly the same problem. Using executeQuery with "SELECT column_name_of_timestamp FROM table" triggers NullPointerException if column_name_of_timestamp of the row is NULL.
row.containsKey("column_name_of_timestamp") returns false if the content is NULL. It returns true when there is a value set.
It's v 2.13.0
User avatar
Lapo
Site Admin
Posts: 21645
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: IDBManager and Null values

Postby Lapo » 05 Apr 2019, 15:03

Values from the database are expected to be non-null, otherwise they can't be populated in the relative SFSObject data structure, using the DBManager.

If your use case requires to work with null results you can bypass the DBManager and simply use the connection directly with a PreparedStatement, and the extracting the results accordingly.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 33 guests