You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@juneau.apache.org by David Goddard <go...@acm.org> on 2017/06/14 18:03:10 UTC

ObjectMap parsing NullPointerException

Hi,

I'm updating some code from Juneau 6.0.1 to 6.2.0-incubating and I'm 
finding that parsing some JSON to an ObjectMap that previously worked 
now fails with a NullPointerException:

   java.lang.NullPointerException
	at org.apache.juneau.ObjectMap.parseReader(ObjectMap.java:192)
	at org.apache.juneau.ObjectMap.<init>(ObjectMap.java:186)

This is the line of application code causing it:

   ObjectMap map = new ObjectMap(new StringReader(json));

The JSON in this case is:

{
   "weatherinsights": [
         {
             "credentials": {
                 "username": "xx",
                 "password": "xx",
                 "host": "twcservice.au-syd.mybluemix.net",
                 "port": 443,
                 "url": "xx"
             },
             "syslog_drain_url": null,
             "label": "weatherinsights",
             "provider": null,
             "plan": "Free-v2",
             "name": "Weather Company Data xx",
             "tags": [
                 "big_data",
                 "ibm_created",
                 "ibm_dedicated_public"
             ]
         }
     ],
    "cloudantNoSQLDB": [
       {
          "name": "xx",
          "label": "cloudantNoSQLDB",
          "plan": "Shared",
          "credentials": {
             "username": "xx",
             "password": "xx",
             "host": "xx-bluemix.cloudant.com",
             "port": 443,
             "url": "xx"
          }
       }
    ]
}

Looking in debug, I see that the failure in ObjectMap is here:

   private void parseReader(Reader r, Parser p) throws ParseException {
	if (p == null)
		p = JsonParser.DEFAULT;
	p.parseIntoMap(r, this, session.string(), session.object());
   }

This fails because the variable, session, is null.  I can't figure out 
why.  Stepping through it in debug, before it gets to this point, I see 
the ObjectMap being initialised here:

	public ObjectMap(BeanSession session) {
		super();
		this.session = session;
	}

In this case, the passed value of session is *not* null:

   {
	BeanContext: {
		id: -981232688,
		beansRequireDefaultConstructor: false,
		beansRequireSerializable: false,
		beansRequireSettersForGetters: false,
		beansRequireSomeProperties: true,
		beanMapPutReturnsOldValue: false,
		beanConstructorVisibility: 'PUBLIC',
		beanClassVisibility: 'PUBLIC',
		beanMethodVisibility: 'PUBLIC',
		beanFieldVisibility: 'PUBLIC',
		useInterfaceProxies: true,
		ignoreUnknownBeanProperties: false,
		ignoreUnknownNullBeanProperties: true,
		ignorePropertiesWithoutSetters: true,
		ignoreInvocationExceptionsOnGetters: false,
		ignoreInvocationExceptionsOnSetters: false,
		useJavaBeanIntrospector: false,
		beanFilters: [
		],
		pojoSwaps: [
		],
		notBeanClasses: [
		],
		implClasses: {
		},
		sortProperties: false,
		locale: 'en_GB',
		timeZone: null,
		mediaType: null
	},
	BeanSession: {
		locale: 'en_GB',
		timeZone: null
	}
   }


However, by the time we get to parseReader, session *is* null.

I'm obviously not ruling out something dumb on my part, but is there any 
obvious issue here, or somewhere for me to look further?

Thanks,

David

Re: ObjectMap parsing NullPointerException

Posted by David Goddard <go...@acm.org>.
Perfect - thanks for the quick fix, working now as expected.

One related item... I want to parse an ObjectMap to an object (we 
initially parse some JSON to an ObjectMap because we don't know what 
object it represents at that stage (we discover that after examining the 
parsed map)).  I've found that Juneau can't implicitly parse an 
ObjectMap to a bean - when I try this, I get a ParseException thrown by 
JsonParserSession.getReader():

   Cannot convert object of type org.apache.juneau.ObjectMap to a Reader

The solution is pretty simple - first convert the ObjectMap back into 
JSON via toString():

	Fails:
	T parsedObject = (T) p.parse(objMap, objectClass);
	Works:
	T parsedObject = (T) p.parse(objMap.toString(), objectClass);

Given that it appaears pretty trivial, I think it might be worth 
changing the parser to allow it to implicitly parse ObjectMap objects 
without the need for the developer to explicitly convert it to JSON. 
Although my knowledge of how the parser code works is only scratching at 
the surface so there may be something I'm missing.

David


On 14/06/2017 21:17, James Bognar wrote:
> I just delivered a fix.  Try it now.
> 
> On Wed, Jun 14, 2017 at 2:35 PM, James Bognar <ja...@salesforce.com>
> wrote:
> 
>> Looks like an existing bug.  Can you open a Jira ticket?
>>
>> On Wed, Jun 14, 2017 at 2:29 PM, James Bognar <james.bognar@salesforce.com
>>> wrote:
>>
>>> Let me try it out.  I'll let you know.
>>>
>>> On Wed, Jun 14, 2017 at 2:03 PM, David Goddard <go...@acm.org> wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm updating some code from Juneau 6.0.1 to 6.2.0-incubating and I'm
>>>> finding that parsing some JSON to an ObjectMap that previously worked now
>>>> fails with a NullPointerException:
>>>>
>>>>    java.lang.NullPointerException
>>>>          at org.apache.juneau.ObjectMap.parseReader(ObjectMap.java:192)
>>>>          at org.apache.juneau.ObjectMap.<init>(ObjectMap.java:186)
>>>>
>>>> This is the line of application code causing it:
>>>>
>>>>    ObjectMap map = new ObjectMap(new StringReader(json));
>>>>
>>>> The JSON in this case is:
>>>>
>>>> {
>>>>    "weatherinsights": [
>>>>          {
>>>>              "credentials": {
>>>>                  "username": "xx",
>>>>                  "password": "xx",
>>>>                  "host": "twcservice.au-syd.mybluemix.net",
>>>>                  "port": 443,
>>>>                  "url": "xx"
>>>>              },
>>>>              "syslog_drain_url": null,
>>>>              "label": "weatherinsights",
>>>>              "provider": null,
>>>>              "plan": "Free-v2",
>>>>              "name": "Weather Company Data xx",
>>>>              "tags": [
>>>>                  "big_data",
>>>>                  "ibm_created",
>>>>                  "ibm_dedicated_public"
>>>>              ]
>>>>          }
>>>>      ],
>>>>     "cloudantNoSQLDB": [
>>>>        {
>>>>           "name": "xx",
>>>>           "label": "cloudantNoSQLDB",
>>>>           "plan": "Shared",
>>>>           "credentials": {
>>>>              "username": "xx",
>>>>              "password": "xx",
>>>>              "host": "xx-bluemix.cloudant.com",
>>>>              "port": 443,
>>>>              "url": "xx"
>>>>           }
>>>>        }
>>>>     ]
>>>> }
>>>>
>>>> Looking in debug, I see that the failure in ObjectMap is here:
>>>>
>>>>    private void parseReader(Reader r, Parser p) throws ParseException {
>>>>          if (p == null)
>>>>                  p = JsonParser.DEFAULT;
>>>>          p.parseIntoMap(r, this, session.string(), session.object());
>>>>    }
>>>>
>>>> This fails because the variable, session, is null.  I can't figure out
>>>> why.  Stepping through it in debug, before it gets to this point, I see the
>>>> ObjectMap being initialised here:
>>>>
>>>>          public ObjectMap(BeanSession session) {
>>>>                  super();
>>>>                  this.session = session;
>>>>          }
>>>>
>>>> In this case, the passed value of session is *not* null:
>>>>
>>>>    {
>>>>          BeanContext: {
>>>>                  id: -981232688,
>>>>                  beansRequireDefaultConstructor: false,
>>>>                  beansRequireSerializable: false,
>>>>                  beansRequireSettersForGetters: false,
>>>>                  beansRequireSomeProperties: true,
>>>>                  beanMapPutReturnsOldValue: false,
>>>>                  beanConstructorVisibility: 'PUBLIC',
>>>>                  beanClassVisibility: 'PUBLIC',
>>>>                  beanMethodVisibility: 'PUBLIC',
>>>>                  beanFieldVisibility: 'PUBLIC',
>>>>                  useInterfaceProxies: true,
>>>>                  ignoreUnknownBeanProperties: false,
>>>>                  ignoreUnknownNullBeanProperties: true,
>>>>                  ignorePropertiesWithoutSetters: true,
>>>>                  ignoreInvocationExceptionsOnGetters: false,
>>>>                  ignoreInvocationExceptionsOnSetters: false,
>>>>                  useJavaBeanIntrospector: false,
>>>>                  beanFilters: [
>>>>                  ],
>>>>                  pojoSwaps: [
>>>>                  ],
>>>>                  notBeanClasses: [
>>>>                  ],
>>>>                  implClasses: {
>>>>                  },
>>>>                  sortProperties: false,
>>>>                  locale: 'en_GB',
>>>>                  timeZone: null,
>>>>                  mediaType: null
>>>>          },
>>>>          BeanSession: {
>>>>                  locale: 'en_GB',
>>>>                  timeZone: null
>>>>          }
>>>>    }
>>>>
>>>>
>>>> However, by the time we get to parseReader, session *is* null.
>>>>
>>>> I'm obviously not ruling out something dumb on my part, but is there any
>>>> obvious issue here, or somewhere for me to look further?
>>>>
>>>> Thanks,
>>>>
>>>> David
>>>>
>>>
>>>
>>>
>>> --
>>> James Bognar
>>>
>>
>>
>>
>> --
>> James Bognar
>>
> 
> 
> 


Re: ObjectMap parsing NullPointerException

Posted by James Bognar <ja...@salesforce.com>.
I just delivered a fix.  Try it now.

On Wed, Jun 14, 2017 at 2:35 PM, James Bognar <ja...@salesforce.com>
wrote:

> Looks like an existing bug.  Can you open a Jira ticket?
>
> On Wed, Jun 14, 2017 at 2:29 PM, James Bognar <james.bognar@salesforce.com
> > wrote:
>
>> Let me try it out.  I'll let you know.
>>
>> On Wed, Jun 14, 2017 at 2:03 PM, David Goddard <go...@acm.org> wrote:
>>
>>> Hi,
>>>
>>> I'm updating some code from Juneau 6.0.1 to 6.2.0-incubating and I'm
>>> finding that parsing some JSON to an ObjectMap that previously worked now
>>> fails with a NullPointerException:
>>>
>>>   java.lang.NullPointerException
>>>         at org.apache.juneau.ObjectMap.parseReader(ObjectMap.java:192)
>>>         at org.apache.juneau.ObjectMap.<init>(ObjectMap.java:186)
>>>
>>> This is the line of application code causing it:
>>>
>>>   ObjectMap map = new ObjectMap(new StringReader(json));
>>>
>>> The JSON in this case is:
>>>
>>> {
>>>   "weatherinsights": [
>>>         {
>>>             "credentials": {
>>>                 "username": "xx",
>>>                 "password": "xx",
>>>                 "host": "twcservice.au-syd.mybluemix.net",
>>>                 "port": 443,
>>>                 "url": "xx"
>>>             },
>>>             "syslog_drain_url": null,
>>>             "label": "weatherinsights",
>>>             "provider": null,
>>>             "plan": "Free-v2",
>>>             "name": "Weather Company Data xx",
>>>             "tags": [
>>>                 "big_data",
>>>                 "ibm_created",
>>>                 "ibm_dedicated_public"
>>>             ]
>>>         }
>>>     ],
>>>    "cloudantNoSQLDB": [
>>>       {
>>>          "name": "xx",
>>>          "label": "cloudantNoSQLDB",
>>>          "plan": "Shared",
>>>          "credentials": {
>>>             "username": "xx",
>>>             "password": "xx",
>>>             "host": "xx-bluemix.cloudant.com",
>>>             "port": 443,
>>>             "url": "xx"
>>>          }
>>>       }
>>>    ]
>>> }
>>>
>>> Looking in debug, I see that the failure in ObjectMap is here:
>>>
>>>   private void parseReader(Reader r, Parser p) throws ParseException {
>>>         if (p == null)
>>>                 p = JsonParser.DEFAULT;
>>>         p.parseIntoMap(r, this, session.string(), session.object());
>>>   }
>>>
>>> This fails because the variable, session, is null.  I can't figure out
>>> why.  Stepping through it in debug, before it gets to this point, I see the
>>> ObjectMap being initialised here:
>>>
>>>         public ObjectMap(BeanSession session) {
>>>                 super();
>>>                 this.session = session;
>>>         }
>>>
>>> In this case, the passed value of session is *not* null:
>>>
>>>   {
>>>         BeanContext: {
>>>                 id: -981232688,
>>>                 beansRequireDefaultConstructor: false,
>>>                 beansRequireSerializable: false,
>>>                 beansRequireSettersForGetters: false,
>>>                 beansRequireSomeProperties: true,
>>>                 beanMapPutReturnsOldValue: false,
>>>                 beanConstructorVisibility: 'PUBLIC',
>>>                 beanClassVisibility: 'PUBLIC',
>>>                 beanMethodVisibility: 'PUBLIC',
>>>                 beanFieldVisibility: 'PUBLIC',
>>>                 useInterfaceProxies: true,
>>>                 ignoreUnknownBeanProperties: false,
>>>                 ignoreUnknownNullBeanProperties: true,
>>>                 ignorePropertiesWithoutSetters: true,
>>>                 ignoreInvocationExceptionsOnGetters: false,
>>>                 ignoreInvocationExceptionsOnSetters: false,
>>>                 useJavaBeanIntrospector: false,
>>>                 beanFilters: [
>>>                 ],
>>>                 pojoSwaps: [
>>>                 ],
>>>                 notBeanClasses: [
>>>                 ],
>>>                 implClasses: {
>>>                 },
>>>                 sortProperties: false,
>>>                 locale: 'en_GB',
>>>                 timeZone: null,
>>>                 mediaType: null
>>>         },
>>>         BeanSession: {
>>>                 locale: 'en_GB',
>>>                 timeZone: null
>>>         }
>>>   }
>>>
>>>
>>> However, by the time we get to parseReader, session *is* null.
>>>
>>> I'm obviously not ruling out something dumb on my part, but is there any
>>> obvious issue here, or somewhere for me to look further?
>>>
>>> Thanks,
>>>
>>> David
>>>
>>
>>
>>
>> --
>> James Bognar
>>
>
>
>
> --
> James Bognar
>



-- 
James Bognar

Re: ObjectMap parsing NullPointerException

Posted by James Bognar <ja...@salesforce.com>.
Looks like an existing bug.  Can you open a Jira ticket?

On Wed, Jun 14, 2017 at 2:29 PM, James Bognar <ja...@salesforce.com>
wrote:

> Let me try it out.  I'll let you know.
>
> On Wed, Jun 14, 2017 at 2:03 PM, David Goddard <go...@acm.org> wrote:
>
>> Hi,
>>
>> I'm updating some code from Juneau 6.0.1 to 6.2.0-incubating and I'm
>> finding that parsing some JSON to an ObjectMap that previously worked now
>> fails with a NullPointerException:
>>
>>   java.lang.NullPointerException
>>         at org.apache.juneau.ObjectMap.parseReader(ObjectMap.java:192)
>>         at org.apache.juneau.ObjectMap.<init>(ObjectMap.java:186)
>>
>> This is the line of application code causing it:
>>
>>   ObjectMap map = new ObjectMap(new StringReader(json));
>>
>> The JSON in this case is:
>>
>> {
>>   "weatherinsights": [
>>         {
>>             "credentials": {
>>                 "username": "xx",
>>                 "password": "xx",
>>                 "host": "twcservice.au-syd.mybluemix.net",
>>                 "port": 443,
>>                 "url": "xx"
>>             },
>>             "syslog_drain_url": null,
>>             "label": "weatherinsights",
>>             "provider": null,
>>             "plan": "Free-v2",
>>             "name": "Weather Company Data xx",
>>             "tags": [
>>                 "big_data",
>>                 "ibm_created",
>>                 "ibm_dedicated_public"
>>             ]
>>         }
>>     ],
>>    "cloudantNoSQLDB": [
>>       {
>>          "name": "xx",
>>          "label": "cloudantNoSQLDB",
>>          "plan": "Shared",
>>          "credentials": {
>>             "username": "xx",
>>             "password": "xx",
>>             "host": "xx-bluemix.cloudant.com",
>>             "port": 443,
>>             "url": "xx"
>>          }
>>       }
>>    ]
>> }
>>
>> Looking in debug, I see that the failure in ObjectMap is here:
>>
>>   private void parseReader(Reader r, Parser p) throws ParseException {
>>         if (p == null)
>>                 p = JsonParser.DEFAULT;
>>         p.parseIntoMap(r, this, session.string(), session.object());
>>   }
>>
>> This fails because the variable, session, is null.  I can't figure out
>> why.  Stepping through it in debug, before it gets to this point, I see the
>> ObjectMap being initialised here:
>>
>>         public ObjectMap(BeanSession session) {
>>                 super();
>>                 this.session = session;
>>         }
>>
>> In this case, the passed value of session is *not* null:
>>
>>   {
>>         BeanContext: {
>>                 id: -981232688,
>>                 beansRequireDefaultConstructor: false,
>>                 beansRequireSerializable: false,
>>                 beansRequireSettersForGetters: false,
>>                 beansRequireSomeProperties: true,
>>                 beanMapPutReturnsOldValue: false,
>>                 beanConstructorVisibility: 'PUBLIC',
>>                 beanClassVisibility: 'PUBLIC',
>>                 beanMethodVisibility: 'PUBLIC',
>>                 beanFieldVisibility: 'PUBLIC',
>>                 useInterfaceProxies: true,
>>                 ignoreUnknownBeanProperties: false,
>>                 ignoreUnknownNullBeanProperties: true,
>>                 ignorePropertiesWithoutSetters: true,
>>                 ignoreInvocationExceptionsOnGetters: false,
>>                 ignoreInvocationExceptionsOnSetters: false,
>>                 useJavaBeanIntrospector: false,
>>                 beanFilters: [
>>                 ],
>>                 pojoSwaps: [
>>                 ],
>>                 notBeanClasses: [
>>                 ],
>>                 implClasses: {
>>                 },
>>                 sortProperties: false,
>>                 locale: 'en_GB',
>>                 timeZone: null,
>>                 mediaType: null
>>         },
>>         BeanSession: {
>>                 locale: 'en_GB',
>>                 timeZone: null
>>         }
>>   }
>>
>>
>> However, by the time we get to parseReader, session *is* null.
>>
>> I'm obviously not ruling out something dumb on my part, but is there any
>> obvious issue here, or somewhere for me to look further?
>>
>> Thanks,
>>
>> David
>>
>
>
>
> --
> James Bognar
>



-- 
James Bognar

Re: ObjectMap parsing NullPointerException

Posted by James Bognar <ja...@salesforce.com>.
Let me try it out.  I'll let you know.

On Wed, Jun 14, 2017 at 2:03 PM, David Goddard <go...@acm.org> wrote:

> Hi,
>
> I'm updating some code from Juneau 6.0.1 to 6.2.0-incubating and I'm
> finding that parsing some JSON to an ObjectMap that previously worked now
> fails with a NullPointerException:
>
>   java.lang.NullPointerException
>         at org.apache.juneau.ObjectMap.parseReader(ObjectMap.java:192)
>         at org.apache.juneau.ObjectMap.<init>(ObjectMap.java:186)
>
> This is the line of application code causing it:
>
>   ObjectMap map = new ObjectMap(new StringReader(json));
>
> The JSON in this case is:
>
> {
>   "weatherinsights": [
>         {
>             "credentials": {
>                 "username": "xx",
>                 "password": "xx",
>                 "host": "twcservice.au-syd.mybluemix.net",
>                 "port": 443,
>                 "url": "xx"
>             },
>             "syslog_drain_url": null,
>             "label": "weatherinsights",
>             "provider": null,
>             "plan": "Free-v2",
>             "name": "Weather Company Data xx",
>             "tags": [
>                 "big_data",
>                 "ibm_created",
>                 "ibm_dedicated_public"
>             ]
>         }
>     ],
>    "cloudantNoSQLDB": [
>       {
>          "name": "xx",
>          "label": "cloudantNoSQLDB",
>          "plan": "Shared",
>          "credentials": {
>             "username": "xx",
>             "password": "xx",
>             "host": "xx-bluemix.cloudant.com",
>             "port": 443,
>             "url": "xx"
>          }
>       }
>    ]
> }
>
> Looking in debug, I see that the failure in ObjectMap is here:
>
>   private void parseReader(Reader r, Parser p) throws ParseException {
>         if (p == null)
>                 p = JsonParser.DEFAULT;
>         p.parseIntoMap(r, this, session.string(), session.object());
>   }
>
> This fails because the variable, session, is null.  I can't figure out
> why.  Stepping through it in debug, before it gets to this point, I see the
> ObjectMap being initialised here:
>
>         public ObjectMap(BeanSession session) {
>                 super();
>                 this.session = session;
>         }
>
> In this case, the passed value of session is *not* null:
>
>   {
>         BeanContext: {
>                 id: -981232688,
>                 beansRequireDefaultConstructor: false,
>                 beansRequireSerializable: false,
>                 beansRequireSettersForGetters: false,
>                 beansRequireSomeProperties: true,
>                 beanMapPutReturnsOldValue: false,
>                 beanConstructorVisibility: 'PUBLIC',
>                 beanClassVisibility: 'PUBLIC',
>                 beanMethodVisibility: 'PUBLIC',
>                 beanFieldVisibility: 'PUBLIC',
>                 useInterfaceProxies: true,
>                 ignoreUnknownBeanProperties: false,
>                 ignoreUnknownNullBeanProperties: true,
>                 ignorePropertiesWithoutSetters: true,
>                 ignoreInvocationExceptionsOnGetters: false,
>                 ignoreInvocationExceptionsOnSetters: false,
>                 useJavaBeanIntrospector: false,
>                 beanFilters: [
>                 ],
>                 pojoSwaps: [
>                 ],
>                 notBeanClasses: [
>                 ],
>                 implClasses: {
>                 },
>                 sortProperties: false,
>                 locale: 'en_GB',
>                 timeZone: null,
>                 mediaType: null
>         },
>         BeanSession: {
>                 locale: 'en_GB',
>                 timeZone: null
>         }
>   }
>
>
> However, by the time we get to parseReader, session *is* null.
>
> I'm obviously not ruling out something dumb on my part, but is there any
> obvious issue here, or somewhere for me to look further?
>
> Thanks,
>
> David
>



-- 
James Bognar