[OLINGO-449] Fix NPE in JPAEdmMappingModelService
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/2fd3f0fe Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/2fd3f0fe Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/2fd3f0fe Branch: refs/heads/Olingo-129_PocJpaDataStore Commit: 2fd3f0fee71eee810f8f7d9ce33631fcea60f5c5 Parents: 7ab8cd9 Author: mibo <[email protected]> Authored: Mon Oct 6 10:45:52 2014 +0200 Committer: mibo <[email protected]> Committed: Mon Oct 6 10:45:52 2014 +0200 ---------------------------------------------------------------------- .../access/model/JPAEdmMappingModelService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/2fd3f0fe/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelService.java ---------------------------------------------------------------------- diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelService.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelService.java index 8bec453..4ac568b 100644 --- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelService.java +++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelService.java @@ -19,6 +19,7 @@ package org.apache.olingo.odata2.jpa.processor.core.access.model; import java.io.InputStream; +import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -52,7 +53,7 @@ public class JPAEdmMappingModelService implements JPAEdmMappingModelAccess { } } - mappingModelExists = mappingModelName != null || mappingModelStream != null ? true : false; + mappingModelExists = mappingModelName != null || mappingModelStream != null; } @Override @@ -180,13 +181,14 @@ public class JPAEdmMappingModelService implements JPAEdmMappingModelAccess { } private JPAEntityTypeMapType searchJPAEntityTypeMapType(final String jpaEntityTypeName) { - for (JPAEntityTypeMapType jpaEntityType : mappingModel.getPersistenceUnit().getJPAEntityTypes() - .getJPAEntityType()) { - if (jpaEntityType.getName().equals(jpaEntityTypeName)) { - return jpaEntityType; + if(mappingModel != null) { + List<JPAEntityTypeMapType> types = mappingModel.getPersistenceUnit().getJPAEntityTypes().getJPAEntityType(); + for (JPAEntityTypeMapType jpaEntityType : types) { + if (jpaEntityType.getName().equals(jpaEntityTypeName)) { + return jpaEntityType; + } } } - return null; } @@ -205,8 +207,7 @@ public class JPAEdmMappingModelService implements JPAEdmMappingModelAccess { if (mappingModelStream != null) { return mappingModelStream; } - InputStream is = JPAEdmMappingModelService.class.getClassLoader().getResourceAsStream("../../" + mappingModelName); - return is; + return JPAEdmMappingModelService.class.getClassLoader().getResourceAsStream("../../" + mappingModelName); }
