edgarRd commented on code in PR #4663:
URL: https://github.com/apache/iceberg/pull/4663#discussion_r861863657


##########
spark/v2.4/spark/src/main/java/org/apache/iceberg/spark/SparkValueConverter.java:
##########
@@ -58,20 +58,32 @@ public static Object convert(Type type, Object object) {
       case LIST:
         List<Object> convertedList = Lists.newArrayList();
         List<?> list = (List<?>) object;
-        for (Object element : list) {
-          convertedList.add(convert(type.asListType().elementType(), element));
+        try {
+          for (Object element : list) {
+            convertedList.add(convert(type.asListType().elementType(), 
element));
+          }
+          return convertedList;
+        } catch (NullPointerException npe) {
+          // Scala 2.11 fix: Catch NPE as internal value could be null and 
scala wrapper does not
+          // evaluate until iteration.
+          return null;
         }
-        return convertedList;
 
       case MAP:
         Map<Object, Object> convertedMap = Maps.newLinkedHashMap();
         Map<?, ?> map = (Map<?, ?>) object;
-        for (Map.Entry<?, ?> entry : map.entrySet()) {
-          convertedMap.put(
-              convert(type.asMapType().keyType(), entry.getKey()),
-              convert(type.asMapType().valueType(), entry.getValue()));
+        try {
+          for (Map.Entry<?, ?> entry : map.entrySet()) {
+            convertedMap.put(
+                convert(type.asMapType().keyType(), entry.getKey()),
+                convert(type.asMapType().valueType(), entry.getValue()));
+          }
+          return convertedMap;
+        } catch (NullPointerException npe) {
+          // Scala 2.11 fix: Catch NPE as internal value could be null and 
scala wrapper does not
+          // evaluate until iteration.

Review Comment:
   Unfortunately, I don't think we can access the underlying map that is 
`null`. The line throwing the NPE is 
https://github.com/scala/scala/blob/2.11.x/src/library/scala/collection/convert/Wrappers.scala#L184
 - here the `underlying.iterator` throws NPE as `underlying` is `null`, similar 
to any other Map method call that uses `underlying` such as `Map#size()`.
   In fact, `Map#entrySet` returns a valid anonymous set but when the 
`iterator()` method is called the NPE is raised.
   
   I wonder if with reflection you can check for nullity on `underlying` but I 
think that's no better approach. Open to suggestions. Thanks!
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to