You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by David Ventimiglia <dv...@gmail.com> on 2014/10/07 04:59:10 UTC

NPE when adding more then one EntityContainer to a Schema?

Hi,

I'm working toward my particular goals by slowly adapting some of the
sample code that's provided with Olingo Java v2.  In particular, I'm
starting with the sample application, whose MyEdmProvider has entities
related to cars (manufacturer, etc.).  I notice that that sample
EdmProvider only creates one EntityContainer (all the other things,
EntitySets, AssociationSets, etc., are added to it), which is added to the
Schema.  I tried creating another EntityContainer and adding it to the
List<EntityContainer> that is passed into Schema.setEntityContainers.  When
I do this, evidently a NullPointerException is thrown somewhere when I try
to access the Atom Service document.  The Odata $metadata document was
provided without issue, however, with all the EntityContainers that I
expected.  When I try the Atom Service document, however, the content has a
<message> tag with the phrase "A NullPointerException was thrown" or
something like that, yet nothing appears in the server log.  I'll try to
cook up a representative example, but would anyone know why this is
occurring?  Thanks!

Best,
David

Re: NPE when adding more then one EntityContainer to a Schema?

Posted by "Bolz, Michael" <mi...@sap.com>.
Hi David,

Thanks for investigation in the problem and sharing the solution.
According to your description I created issue OLINGO-455 (https://issues.apache.org/jira/browse/OLINGO-455).
I think it will be discussed within the community but IMHO it is a best practice to return empty Lists instead of NULL values and hence the current behaviour should be changed.

Kind regards,
Michael

From: David Ventimiglia <dv...@gmail.com>>
Reply-To: "user@olingo.apache.org<ma...@olingo.apache.org>" <us...@olingo.apache.org>>
Date: Tuesday 7 October 2014 14:31
To: "user@olingo.apache.org<ma...@olingo.apache.org>" <us...@olingo.apache.org>>
Subject: Re: NPE when adding more then one EntityContainer to a Schema?

Hi,

OK, I fixed my problem.

First, the `catch (Exception e)' is in org.apache.olingo.odata2.core.ep.AtomEntityProvider.writeServiceDocument line 155.  Adding in e.printStackTrace(System.err), I see the actual NPE is thrown from org.apache.olingo.odata2.core.edm.provider.EdmServiceMetadataImplProv.getEntitySetInfos line 152.  If you don't call setEntitySets on your EntityContainer then getEntitySets returns Null, in which case trying to get a java.util.Iterator throws an NPE.  Guessing that something similar might apply for AssociationSets and FunctionImports, I called the three methods setXXXSets (for entities, associations, and functions) passing an empty ArrayList in each time, which banished the NPE.

You might consider having getEntitySets return an empty List when it hasn't been set or has been set with a Null, in order to protect callers.  In any case, I'm good!

Cheers,
David

On Tue, Oct 7, 2014 at 4:54 AM, David Ventimiglia <dv...@gmail.com>> wrote:
Hi,

Yes, I've confirmed that one only has to create a new, empty EntityContainer within MyEdmProvider (as illustrated here<http://olingo.apache.org/doc/odata2/tutorials/basicread.html>), give it a name (say, "foo") and add it to the Schema.  Do that, and requesting the Atom Service document provokes a NullPointerException.  The actual response is:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code/>
<message xml:lang="en-US">
An exception of type 'NullPointerException' occurred.
</message>
</error>

Groping around in the source code, I swear I thought I found a place where the Service document-handling code where `Exception e' is caught and an ODataException is rethrown with the EXCEPTION_OCCURRED message, but I can't for the life of me find it again.  I'll keep looking.  Thanks!

Best,
David

On Mon, Oct 6, 2014 at 7:59 PM, David Ventimiglia <dv...@gmail.com>> wrote:
Hi,

I'm working toward my particular goals by slowly adapting some of the sample code that's provided with Olingo Java v2.  In particular, I'm starting with the sample application, whose MyEdmProvider has entities related to cars (manufacturer, etc.).  I notice that that sample EdmProvider only creates one EntityContainer (all the other things, EntitySets, AssociationSets, etc., are added to it), which is added to the Schema.  I tried creating another EntityContainer and adding it to the List<EntityContainer> that is passed into Schema.setEntityContainers.  When I do this, evidently a NullPointerException is thrown somewhere when I try to access the Atom Service document.  The Odata $metadata document was provided without issue, however, with all the EntityContainers that I expected.  When I try the Atom Service document, however, the content has a <message> tag with the phrase "A NullPointerException was thrown" or something like that, yet nothing appears in the server log.  I'll try to cook up a representative example, but would anyone know why this is occurring?  Thanks!

Best,
David



Re: NPE when adding more then one EntityContainer to a Schema?

Posted by "Bolz, Michael" <mi...@sap.com>.
Hi David,

Thanks for investigation in the problem and sharing the solution.
According to your description I created issue OLINGO-455 (https://issues.apache.org/jira/browse/OLINGO-455).
I think it will be discussed within the community but IMHO it is a best practice to return empty Lists instead of NULL values and hence the current behaviour should be changed.

Kind regards,
Michael

From: David Ventimiglia <dv...@gmail.com>>
Reply-To: "user@olingo.apache.org<ma...@olingo.apache.org>" <us...@olingo.apache.org>>
Date: Tuesday 7 October 2014 14:31
To: "user@olingo.apache.org<ma...@olingo.apache.org>" <us...@olingo.apache.org>>
Subject: Re: NPE when adding more then one EntityContainer to a Schema?

Hi,

OK, I fixed my problem.

First, the `catch (Exception e)' is in org.apache.olingo.odata2.core.ep.AtomEntityProvider.writeServiceDocument line 155.  Adding in e.printStackTrace(System.err), I see the actual NPE is thrown from org.apache.olingo.odata2.core.edm.provider.EdmServiceMetadataImplProv.getEntitySetInfos line 152.  If you don't call setEntitySets on your EntityContainer then getEntitySets returns Null, in which case trying to get a java.util.Iterator throws an NPE.  Guessing that something similar might apply for AssociationSets and FunctionImports, I called the three methods setXXXSets (for entities, associations, and functions) passing an empty ArrayList in each time, which banished the NPE.

You might consider having getEntitySets return an empty List when it hasn't been set or has been set with a Null, in order to protect callers.  In any case, I'm good!

Cheers,
David

On Tue, Oct 7, 2014 at 4:54 AM, David Ventimiglia <dv...@gmail.com>> wrote:
Hi,

Yes, I've confirmed that one only has to create a new, empty EntityContainer within MyEdmProvider (as illustrated here<http://olingo.apache.org/doc/odata2/tutorials/basicread.html>), give it a name (say, "foo") and add it to the Schema.  Do that, and requesting the Atom Service document provokes a NullPointerException.  The actual response is:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code/>
<message xml:lang="en-US">
An exception of type 'NullPointerException' occurred.
</message>
</error>

Groping around in the source code, I swear I thought I found a place where the Service document-handling code where `Exception e' is caught and an ODataException is rethrown with the EXCEPTION_OCCURRED message, but I can't for the life of me find it again.  I'll keep looking.  Thanks!

Best,
David

On Mon, Oct 6, 2014 at 7:59 PM, David Ventimiglia <dv...@gmail.com>> wrote:
Hi,

I'm working toward my particular goals by slowly adapting some of the sample code that's provided with Olingo Java v2.  In particular, I'm starting with the sample application, whose MyEdmProvider has entities related to cars (manufacturer, etc.).  I notice that that sample EdmProvider only creates one EntityContainer (all the other things, EntitySets, AssociationSets, etc., are added to it), which is added to the Schema.  I tried creating another EntityContainer and adding it to the List<EntityContainer> that is passed into Schema.setEntityContainers.  When I do this, evidently a NullPointerException is thrown somewhere when I try to access the Atom Service document.  The Odata $metadata document was provided without issue, however, with all the EntityContainers that I expected.  When I try the Atom Service document, however, the content has a <message> tag with the phrase "A NullPointerException was thrown" or something like that, yet nothing appears in the server log.  I'll try to cook up a representative example, but would anyone know why this is occurring?  Thanks!

Best,
David



Re: NPE when adding more then one EntityContainer to a Schema?

Posted by David Ventimiglia <dv...@gmail.com>.
Hi,

OK, I fixed my problem.

First, the `catch (Exception e)' is
in org.apache.olingo.odata2.core.ep.AtomEntityProvider.writeServiceDocument
line 155.  Adding in e.printStackTrace(System.err), I see the actual NPE is
thrown
from org.apache.olingo.odata2.core.edm.provider.EdmServiceMetadataImplProv.getEntitySetInfos
line 152.  If you don't call setEntitySets on your EntityContainer then
getEntitySets returns Null, in which case trying to get a
java.util.Iterator throws an NPE.  Guessing that something similar might
apply for AssociationSets and FunctionImports, I called the three methods
setXXXSets (for entities, associations, and functions) passing an empty
ArrayList in each time, which banished the NPE.

You might consider having getEntitySets return an empty List when it hasn't
been set or has been set with a Null, in order to protect callers.  In any
case, I'm good!

Cheers,
David

On Tue, Oct 7, 2014 at 4:54 AM, David Ventimiglia <dv...@gmail.com>
wrote:

> Hi,
>
> Yes, I've confirmed that one only has to create a new, empty
> EntityContainer within MyEdmProvider (as illustrated here
> <http://olingo.apache.org/doc/odata2/tutorials/basicread.html>), give it
> a name (say, "foo") and add it to the Schema.  Do that, and requesting the
> Atom Service document provokes a NullPointerException.  The actual response
> is:
>
> <error xmlns="
> http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
> <code/>
> <message xml:lang="en-US">
> An exception of type 'NullPointerException' occurred.
> </message>
> </error>
>
> Groping around in the source code, I swear I thought I found a place where
> the Service document-handling code where `Exception e' is caught and an
> ODataException is rethrown with the EXCEPTION_OCCURRED message, but I can't
> for the life of me find it again.  I'll keep looking.  Thanks!
>
> Best,
> David
>
> On Mon, Oct 6, 2014 at 7:59 PM, David Ventimiglia <dv...@gmail.com>
> wrote:
>
>> Hi,
>>
>> I'm working toward my particular goals by slowly adapting some of the
>> sample code that's provided with Olingo Java v2.  In particular, I'm
>> starting with the sample application, whose MyEdmProvider has entities
>> related to cars (manufacturer, etc.).  I notice that that sample
>> EdmProvider only creates one EntityContainer (all the other things,
>> EntitySets, AssociationSets, etc., are added to it), which is added to the
>> Schema.  I tried creating another EntityContainer and adding it to the
>> List<EntityContainer> that is passed into Schema.setEntityContainers.  When
>> I do this, evidently a NullPointerException is thrown somewhere when I try
>> to access the Atom Service document.  The Odata $metadata document was
>> provided without issue, however, with all the EntityContainers that I
>> expected.  When I try the Atom Service document, however, the content has a
>> <message> tag with the phrase "A NullPointerException was thrown" or
>> something like that, yet nothing appears in the server log.  I'll try to
>> cook up a representative example, but would anyone know why this is
>> occurring?  Thanks!
>>
>> Best,
>> David
>>
>
>

Re: NPE when adding more then one EntityContainer to a Schema?

Posted by David Ventimiglia <dv...@gmail.com>.
Hi,

Yes, I've confirmed that one only has to create a new, empty
EntityContainer within MyEdmProvider (as illustrated here
<http://olingo.apache.org/doc/odata2/tutorials/basicread.html>), give it a
name (say, "foo") and add it to the Schema.  Do that, and requesting the
Atom Service document provokes a NullPointerException.  The actual response
is:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata
">
<code/>
<message xml:lang="en-US">
An exception of type 'NullPointerException' occurred.
</message>
</error>

Groping around in the source code, I swear I thought I found a place where
the Service document-handling code where `Exception e' is caught and an
ODataException is rethrown with the EXCEPTION_OCCURRED message, but I can't
for the life of me find it again.  I'll keep looking.  Thanks!

Best,
David

On Mon, Oct 6, 2014 at 7:59 PM, David Ventimiglia <dv...@gmail.com>
wrote:

> Hi,
>
> I'm working toward my particular goals by slowly adapting some of the
> sample code that's provided with Olingo Java v2.  In particular, I'm
> starting with the sample application, whose MyEdmProvider has entities
> related to cars (manufacturer, etc.).  I notice that that sample
> EdmProvider only creates one EntityContainer (all the other things,
> EntitySets, AssociationSets, etc., are added to it), which is added to the
> Schema.  I tried creating another EntityContainer and adding it to the
> List<EntityContainer> that is passed into Schema.setEntityContainers.  When
> I do this, evidently a NullPointerException is thrown somewhere when I try
> to access the Atom Service document.  The Odata $metadata document was
> provided without issue, however, with all the EntityContainers that I
> expected.  When I try the Atom Service document, however, the content has a
> <message> tag with the phrase "A NullPointerException was thrown" or
> something like that, yet nothing appears in the server log.  I'll try to
> cook up a representative example, but would anyone know why this is
> occurring?  Thanks!
>
> Best,
> David
>