Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
SQOOP-3435 Avoid NullPointerException due to different JSONObject lib…
Browse files Browse the repository at this point in the history
…rary 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
  • Loading branch information
TAK LON WU committed Apr 2, 2019
1 parent 0216f7f commit 6024180
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/java/org/apache/sqoop/util/SqoopJsonUtil.java
Expand Up @@ -18,6 +18,8 @@

package org.apache.sqoop.util;

import static java.util.Collections.emptyMap;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -40,7 +42,8 @@ private SqoopJsonUtil() {
}

public static String getJsonStringforMap(Map<String, String> map) {
JSONObject pathPartMap = new JSONObject(map);
Map<String, String> mapToUse = (map == null) ? emptyMap() : map;
JSONObject pathPartMap = new JSONObject(mapToUse);
return pathPartMap.toString();
}

Expand All @@ -49,7 +52,7 @@ public static Map<String, String> getMapforJsonString(String mapJsonStr) {
final Map<String, String> result;
try {
if (isEmptyJSON(mapJsonStr)) {
result = Collections.emptyMap();
result = emptyMap();
} else {
ObjectMapper mapper = new ObjectMapper();
result = mapper.readValue(mapJsonStr,
Expand Down

0 comments on commit 6024180

Please sign in to comment.