Repository: olingo-odata2
Updated Branches:
  refs/heads/master a189877b6 -> 992e42469


Fix NPE and Resource leaks.

Signed-off-by: Chandan V A <[email protected]>

Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/992e4246
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/992e4246
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/992e4246

Branch: refs/heads/master
Commit: 992e424696bcb89430e95d84a7dcc288712acc47
Parents: a189877
Author: Chandan V A <[email protected]>
Authored: Tue May 19 15:04:48 2015 +0530
Committer: Chandan V A <[email protected]>
Committed: Tue May 19 15:04:48 2015 +0530

----------------------------------------------------------------------
 .../core/access/data/JPAEntityParser.java       | 24 ++++++++++++++++----
 .../access/model/JPAEdmMappingModelService.java | 13 ++++++++---
 .../core/access/model/JPAEdmNameBuilder.java    |  7 ++++--
 .../processor/core/edm/ODataJPAEdmProvider.java |  3 ++-
 4 files changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/992e4246/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
index 7f4eed6..03ef879 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
@@ -262,13 +262,14 @@ public final class JPAEntityParser {
   }
 
   public static String getString(final Clob clob) throws 
ODataJPARuntimeException {
+    Reader stringReader = null;
     try {
 
       if (clob == null) {
         return null;
       }
 
-      Reader stringReader = clob.getCharacterStream();
+      stringReader = clob.getCharacterStream();
       StringWriter buffer = null;
       long clobSize = clob.length();
       long remainingClobSize = clobSize;
@@ -283,7 +284,6 @@ public final class JPAEntityParser {
         buffer = new StringWriter((int) clobSize);
         len = (int) clobSize;
       }
-      stringReader = clob.getCharacterStream();
       char c[] = new char[len];
       while (remainingClobSize > len) {
         stringReader.read(c, off, len);
@@ -309,18 +309,26 @@ public final class JPAEntityParser {
       throw 
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
 e);
     } catch (IOException e) {
       throw 
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
 e);
+    } finally {
+      if (stringReader != null) {
+        try {
+          stringReader.close();
+        } catch (IOException e) {
+          //do nothing
+        }
+      }
     }
 
   }
 
   public static byte[] getBytes(final Blob blob) throws 
ODataJPARuntimeException {
+    InputStream is = null;
+    ByteArrayOutputStream buffer = null;
     try {
 
       if (blob == null) {
         return null;
       }
-      InputStream is = null;
-      ByteArrayOutputStream buffer = null;
 
       long blobSize = blob.length();
       long remainingBlobSize = blobSize;
@@ -361,6 +369,14 @@ public final class JPAEntityParser {
       throw 
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
 e);
     } catch (IOException e) {
       throw 
ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION,
 e);
+    } finally {
+      if (is != null) {
+        try {
+          is.close();
+        } catch (IOException e) {
+          // do nothing
+        }
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/992e4246/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 4ac568b..33e3fff 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
@@ -18,6 +18,7 @@
  
******************************************************************************/
 package org.apache.olingo.odata2.jpa.processor.core.access.model;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 
@@ -58,14 +59,14 @@ public class JPAEdmMappingModelService implements 
JPAEdmMappingModelAccess {
 
   @Override
   public void loadMappingModel() {
-
+    InputStream is = null;
     if (mappingModelExists) {
       JAXBContext context;
       try {
         context = JAXBContext.newInstance(JPAEdmMappingModel.class);
 
         Unmarshaller unmarshaller = context.createUnmarshaller();
-        InputStream is = loadMappingModelInputStream();
+        is = loadMappingModelInputStream();
         if (is == null) {
           mappingModelExists = false;
           return;
@@ -80,6 +81,12 @@ public class JPAEdmMappingModelService implements 
JPAEdmMappingModelAccess {
       } catch (JAXBException e) {
         mappingModelExists = false;
         ODataJPAModelException.throwException(ODataJPAModelException.GENERAL, 
e);
+      } finally {
+        try {
+          is.close();
+        } catch (IOException e) {
+          //do nothing
+        }
       }
     }
   }
@@ -181,7 +188,7 @@ public class JPAEdmMappingModelService implements 
JPAEdmMappingModelAccess {
   }
 
   private JPAEntityTypeMapType searchJPAEntityTypeMapType(final String 
jpaEntityTypeName) {
-    if(mappingModel != null) {
+    if (mappingModel != null) {
       List<JPAEntityTypeMapType> types = 
mappingModel.getPersistenceUnit().getJPAEntityTypes().getJPAEntityType();
       for (JPAEntityTypeMapType jpaEntityType : types) {
         if (jpaEntityType.getName().equals(jpaEntityTypeName)) {

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/992e4246/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
index 72a4594..293c951 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
@@ -152,8 +152,11 @@ public class JPAEdmNameBuilder {
     } else if (propertyName == null) {
       propertyName = jpaAttributeName;
       if (isForeignKey) {
-        propertyName = 
mappingModelAccess.mapJPAAttribute(view.getJPAEdmEntityTypeView().getJPAEntityType().getName(),
-            joinColumnNames[0]);
+        if (mappingModelAccess != null) {
+          propertyName =
+              
mappingModelAccess.mapJPAAttribute(view.getJPAEdmEntityTypeView().getJPAEntityType().getName(),
+                  joinColumnNames[0]);
+        }
         if (propertyName == null) {
           propertyName = FK_PREFIX + UNDERSCORE + joinColumnNames[0];
         }

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/992e4246/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProvider.java
----------------------------------------------------------------------
diff --git 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProvider.java
 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProvider.java
index 101db9b..49ccad7 100644
--- 
a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProvider.java
+++ 
b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProvider.java
@@ -110,9 +110,10 @@ public class ODataJPAEdmProvider extends EdmProvider {
   @Override
   public EntityType getEntityType(final FullQualifiedName edmFQName) throws 
ODataException {
 
-    String strEdmFQName = edmFQName.toString();
+    String strEdmFQName = null;
 
     if (edmFQName != null) {
+      strEdmFQName = edmFQName.toString();
       if (entityTypes.containsKey(strEdmFQName)) {
         return entityTypes.get(strEdmFQName);
       } else if (schemas == null) {

Reply via email to