You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2022/03/12 10:56:11 UTC

[olingo-odata2] branch master updated (c4c1538 -> d597a01)

This is an automated email from the ASF dual-hosted git repository.

mibo pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git.


    from c4c1538  [OLINGO-1559] Fixed type in EdmFacets.java
     new cc8b340  [OLINGO-1219] Fix NullPointerException if given input is null
     new d597a01  [OLINGO-1219] Add support for Instant type

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 odata2-lib/odata-core/pom.xml                                      | 2 +-
 .../main/java/org/apache/olingo/odata2/core/commons/Encoder.java   | 5 ++++-
 .../java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java  | 7 +++++++
 3 files changed, 12 insertions(+), 2 deletions(-)

[olingo-odata2] 01/02: [OLINGO-1219] Fix NullPointerException if given input is null

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mibo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git

commit cc8b340f54f71cdcfc52b667f6005cff7d5b6170
Author: Song Yihan <sy...@gmail.com>
AuthorDate: Wed Jan 3 14:56:11 2018 +0800

    [OLINGO-1219] Fix NullPointerException if given input is null
    
    in current Encoder implementation, if given input is null, an NPE would be thrown
    
    The scenario would be, consider an Entity which key is allowed to be null in Edmx, thus, the data retrieved in data source would be a HashMap only with non-null value, when createEntryKey<-createSelfLink, we generate the key representation from the given data, some of the key would be null and passed to Encoder, which would throw NullPointerException
---
 .../main/java/org/apache/olingo/odata2/core/commons/Encoder.java   | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
index aceb6cf..478b83c 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
@@ -96,7 +96,12 @@ public class Encoder {
    */
   private String encodeInternal(final String input) {
     StringBuilder resultStr = new StringBuilder();
-
+    
+    // avoid NPE if the given input is null
+    if (input == null) {
+        return null;
+    }
+    
     try {
       for (byte utf8Byte : input.getBytes("UTF-8")) {
         final char character = (char) utf8Byte;

[olingo-odata2] 02/02: [OLINGO-1219] Add support for Instant type

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mibo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git

commit d597a019bd5e76ab56e86a4f9980bb77954c3ab1
Author: Song Yihan <sy...@gmail.com>
AuthorDate: Wed Jan 24 11:35:28 2018 +0800

    [OLINGO-1219] Add support for Instant type
    
    Instant type is widely used in Java 8, need to support it
---
 odata2-lib/odata-core/pom.xml                                      | 2 +-
 .../main/java/org/apache/olingo/odata2/core/commons/Encoder.java   | 6 ++----
 .../java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java  | 7 +++++++
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/odata2-lib/odata-core/pom.xml b/odata2-lib/odata-core/pom.xml
index dad0d1c..9e803d2 100644
--- a/odata2-lib/odata-core/pom.xml
+++ b/odata2-lib/odata-core/pom.xml
@@ -88,7 +88,7 @@
 					</instructions>
 				</configuration>
 			</plugin>
-		</plugins>
+    </plugins>
 	</build>
 
 	<profiles>
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
index 478b83c..181cbd7 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/Encoder.java
@@ -95,13 +95,11 @@ public class Encoder {
    * @return encoded representation
    */
   private String encodeInternal(final String input) {
-    StringBuilder resultStr = new StringBuilder();
-    
-    // avoid NPE if the given input is null
     if (input == null) {
         return null;
     }
-    
+
+    StringBuilder resultStr = new StringBuilder();
     try {
       for (byte utf8Byte : input.getBytes("UTF-8")) {
         final char character = (char) utf8Byte;
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
index 07695eb..86378a7 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTimeOffset.java
@@ -19,6 +19,7 @@
 package org.apache.olingo.odata2.core.edm;
 
 import java.sql.Timestamp;
+import java.time.Instant;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.TimeZone;
@@ -150,6 +151,12 @@ public class EdmDateTimeOffset extends AbstractSimpleType {
       milliSeconds = dateTimeValue.getTimeInMillis();
     } else if (value instanceof Long) {
       milliSeconds = (Long) value;
+    } else if (value instanceof Instant) {
+      try {
+        milliSeconds = ((Instant) value).toEpochMilli();
+      } catch (ArithmeticException e) { // in case the Instant is far away from epoch
+        milliSeconds = Long.MAX_VALUE;
+      }
     } else {
       throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass()));
     }