[OLINGO-798] Fix potential nullpointer in client getContainerCase

This commit is contained in:
Christian Amend 2015-10-22 15:06:09 +02:00
parent 9f663baf5c
commit 46cad03fed
2 changed files with 21 additions and 4 deletions

View File

@ -155,11 +155,18 @@ public class ClientCsdlEdmProvider extends CsdlAbstractEdmProvider {
@Override
public CsdlEntityContainerInfo getEntityContainerInfo(final FullQualifiedName entityContainerName)
throws ODataException {
throws ODataException {
for (CsdlSchema schema : xmlSchemas.values()) {
if (schema.getEntityContainer() != null) {
return new CsdlEntityContainerInfo().setContainerName(entityContainerName).setExtendsContainer(
schema.getEntityContainer().getExtendsContainerFQN());
CsdlEntityContainer entityContainer = schema.getEntityContainer();
if (entityContainer != null) {
FullQualifiedName containerFQN;
if (entityContainerName == null) {
containerFQN = new FullQualifiedName(schema.getNamespace(), entityContainer.getName());
} else {
containerFQN = entityContainerName;
}
return new CsdlEntityContainerInfo().setContainerName(containerFQN).setExtendsContainer(
entityContainer.getExtendsContainerFQN());
}
}
return null;

View File

@ -196,6 +196,16 @@ public class MetadataTest extends AbstractTest {
assertEquals("NorthwindEntities", entityContainer.getName());
}
@Test
public void getContainerWithoutCallingGetSchemas() {
final XMLMetadata metadata = getClient().getDeserializer(ContentType.APPLICATION_XML).
toMetadata(getClass().getResourceAsStream("fromdoc1-metadata.xml"));
Edm edm = getClient().getReader().readMetadata(metadata.getSchemaByNsOrAlias());
assertNotNull(edm.getEntityContainer());
}
/**
* Tests Example 85 from CSDL specification.
*/