[1.3 b87] json.type NullPointerException

Confirmed bugs should get a single post here. Check the READ ME FIRST sticky thread for the format.

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice, MapTool BugReport Manager

Forum rules
Posts that do not conform to the READ ME FIRST sticky thread are subject to deletion.
Post Reply
User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

[1.3 b87] json.type NullPointerException

Post by aliasmask »

This is a really old bug, that had a work around until b87 apparently. I'm guessing because of some library updates? Anyway, here's my example:

Code: Select all

[H: a = "[r: Hello]"]
[R: json.type(a)]
This is a string and should return UNKNOWN, but it gives me an error. I'm guessing the function assumes it's an array with NULL data because the stuff between the []'s (or {}'s if done that way) is not formed like an array, which it isn't. Before I could do this:

Code: Select all

[H: jType = json.append("",piece)]
[r: json.type(json.get(jType,0))]
And it would see it as a string and give me the correct type. If the string is an array or object it would also determine that correctly.

It would be nice if a proper fix could be implemented.

tiorthan
Cave Troll
Posts: 84
Joined: Fri Aug 24, 2012 8:56 am
Location: Germany
Contact:

Re: [1.3 b87] json.type NullPointerException

Post by tiorthan »

I'm going look into this after work.

tiorthan
Cave Troll
Posts: 84
Joined: Fri Aug 24, 2012 8:56 am
Location: Germany
Contact:

Re: [1.3 b87] json.type NullPointerException

Post by tiorthan »

It doesn't throw a NullPointerException at me on the SVN version but it tries to evaluate the contents of the string as a roll.
Is that the expected behaviour?

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: [1.3 b87] json.type NullPointerException

Post by aliasmask »

tiorthan wrote:It doesn't throw a NullPointerException at me on the SVN version but it tries to evaluate the contents of the string as a roll.
Is that the expected behaviour?
Thanks for looking in to this. If I type the above in to chat I get:
java.lang.NullPointerException error executing expression json.type(a).
I'm not sure what you mean by evaluate as a roll. The R: is a roll option, but shouldn't be evaluated by json.type.

tiorthan
Cave Troll
Posts: 84
Joined: Fri Aug 24, 2012 8:56 am
Location: Germany
Contact:

Re: [1.3 b87] json.type NullPointerException

Post by tiorthan »

Duh, I just noticed that the parser class files had not been rebuilt after switching branches.

Having everything back to normal there is no null pointer exception (although I get one in b87, too). Json.type does indeed see "[r: ...]" as a malformed json list and complains about it in a proper error message.
Anyhow, I think json.type should never choke on its parameters, that's what the UNKNOWN return value is for. That's fairly easy to fix, I'll have a patch tomorrow.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: [1.3 b87] json.type NullPointerException

Post by aliasmask »

try/catch would be the simplest solution, although a real test of the string would be more appropriate (failure of a correctly formed object or array).

Actually, now that you mention using the dev files I tried b88 and I get this error instead, which is what you first mentioned:
   Error in body of roll.       Statement options (if any): R       Statement Body : json.type(a)

tiorthan
Cave Troll
Posts: 84
Joined: Fri Aug 24, 2012 8:56 am
Location: Germany
Contact:

Re: [1.3 b87] json.type NullPointerException

Post by tiorthan »

I could wrap it in a try but I don't think it should be solved like that.
JSONMacroFunctions.getJSONObjectType() does indeed contain a bug (I have posted a fix in http://forums.rptools.net/viewtopic.php?f=60&t=22436

Internally all json functions can also take non-json parameters, they are converted to a json array containing only one value. The asJSON function that does the conversion assumes that any string starting with a bracket or brace is a json object. I don't think the implicit conversion was a good idea in the first place, but since it is there, the most logical behavior, IMO, would be to fall back to silently treat them as strings if the conversion fails and not to return null, as it is at the moment. However, that would probably require some follow-up changes (at least in getJSONObjectType, patched or no) because it relies on the current behaviour.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: [1.3 b87] json.type NullPointerException

Post by aliasmask »

Yeah, sounds like a good idea. I was aware of that behavior with json.isEmpty, which has been useful as a comparison operator because it was better at handling than (varName == "") given certain conditions (which is the part I don't recall).

Post Reply

Return to “Bug Reports”