From e8971b9f51e26f6822c52d917e8771de73580885 Mon Sep 17 00:00:00 2001 From: TAK LON WU Date: Fri, 29 Mar 2019 15:46:48 -0700 Subject: [PATCH] SQOOP-3435 Avoid NullPointerException due to different JSONObject library in classpath Sqoop is expecting the classpath to have org.json [1] as the dependency but if one uses HADOOP_CLASSPATH to initialize sqoop executor with com.tdunning open json [2] as the resolution of org.json.JSONObject. it failed with NullPointerException 1. https://mvnrepository.com/artifact/org.json/json/20090211 2. https://github.com/tdunning/open-json/blob/rc1.8/src/main/java/org/json/JSONObject.java#L141-L155 --- src/java/org/apache/sqoop/util/SqoopJsonUtil.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/sqoop/util/SqoopJsonUtil.java b/src/java/org/apache/sqoop/util/SqoopJsonUtil.java index adf186b7d..9e8ba95c8 100644 --- a/src/java/org/apache/sqoop/util/SqoopJsonUtil.java +++ b/src/java/org/apache/sqoop/util/SqoopJsonUtil.java @@ -40,7 +40,8 @@ private SqoopJsonUtil() { } public static String getJsonStringforMap(Map map) { - JSONObject pathPartMap = new JSONObject(map); + Map mapToUse = (map == null) ? Collections.emptyMap() : map; + JSONObject pathPartMap = new JSONObject(mapToUse); return pathPartMap.toString(); }