Remove spurious JSONExceptions

This commit is contained in:
Antonin Delpeuch 2018-11-19 18:39:54 +00:00
parent 0d14df1427
commit f48cdb0c13
11 changed files with 22 additions and 64 deletions

View File

@ -45,9 +45,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.tools.tar.TarOutputStream; import org.apache.tools.tar.TarOutputStream;
import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -418,15 +416,10 @@ public abstract class ProjectManager {
initDisplay(jsonObjArray); initDisplay(jsonObjArray);
try { String userMeta = (String)_preferenceStore.get(PreferenceStore.USER_METADATA_KEY);
String userMeta = (String)_preferenceStore.get(PreferenceStore.USER_METADATA_KEY); if (userMeta == null)
if (userMeta == null) return;
return; userMetadataPreference = ParsingUtilities.mapper.createArrayNode();
userMetadataPreference = ParsingUtilities.mapper.createArrayNode();
} catch (JSONException e1) {
logger.warn("wrong definition of userMetadata format. Please use form [{\"name\": \"client name\", \"display\":true}, {\"name\": \"progress\", \"display\":false}]");
logger.error(ExceptionUtils.getFullStackTrace(e1));
}
for (int index = 0; index < userMetadataPreference.size(); index++) { for (int index = 0; index < userMetadataPreference.size(); index++) {
boolean found = false; boolean found = false;

View File

@ -44,7 +44,6 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -95,7 +94,7 @@ public class GetScatterplotCommand extends Command {
} }
} }
public void draw(OutputStream output, Project project, Engine engine, JSONObject o) throws IOException, JSONException { public void draw(OutputStream output, Project project, Engine engine, JSONObject o) throws IOException {
double min_x = 0; double min_x = 0;
double min_y = 0; double min_y = 0;

View File

@ -36,8 +36,6 @@ package com.google.refine.expr.functions.arrays;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.json.JSONException;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.refine.expr.EvalError; import com.google.refine.expr.EvalError;
import com.google.refine.expr.ExpressionUtils; import com.google.refine.expr.ExpressionUtils;
@ -75,12 +73,7 @@ public class Join implements Function {
if (sb.length() > 0) { if (sb.length() > 0) {
sb.append(separator); sb.append(separator);
} }
try { sb.append(JsonValueConverter.convert(a.get(i)).toString());
sb.append(JsonValueConverter.convert(a.get(i)).toString());
} catch (JSONException e) {
return new EvalError(ControlFunctionRegistry.getFunctionName(this) +
" cannot retrieve element " + i + " of array");
}
} }
} else { } else {
for (Object o : ExpressionUtils.toObjectList(v)) { for (Object o : ExpressionUtils.toObjectList(v)) {

View File

@ -44,7 +44,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.poi.POIXMLDocument; import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLException; import org.apache.poi.POIXMLException;
import org.apache.poi.common.usermodel.Hyperlink; import org.apache.poi.common.usermodel.Hyperlink;
@ -54,7 +53,6 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -187,13 +185,9 @@ public class ExcelImporter extends TabularImportingParserBase {
for(int i=0;i<sheets.size();i++) { for(int i=0;i<sheets.size();i++) {
String[] fileNameAndSheetIndex = new String[2]; String[] fileNameAndSheetIndex = new String[2];
try { ObjectNode sheetObj = (ObjectNode) sheets.get(i);
ObjectNode sheetObj = (ObjectNode) sheets.get(i); // value is fileName#sheetIndex
// value is fileName#sheetIndex fileNameAndSheetIndex = sheetObj.get("fileNameAndSheetIndex").asText().split("#");
fileNameAndSheetIndex = sheetObj.get("fileNameAndSheetIndex").asText().split("#");
} catch (JSONException e) {
logger.error(ExceptionUtils.getFullStackTrace(e));
}
if (!fileNameAndSheetIndex[0].equals(fileSource)) if (!fileNameAndSheetIndex[0].equals(fileSource))
continue; continue;

View File

@ -39,7 +39,6 @@ import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import java.util.List; import java.util.List;
import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -150,12 +149,8 @@ abstract public class ImportingParserBase implements ImportingParser {
} }
private void pushImportingOptions(ProjectMetadata metadata, String fileSource, ObjectNode options) { private void pushImportingOptions(ProjectMetadata metadata, String fileSource, ObjectNode options) {
try { options.put("fileSource", fileSource);
options.put("fileSource", fileSource); // set the import options to metadata:
} catch (JSONException e) {
// ignore
}
// set the import options to metadata:
metadata.appendImportOptionMetadata(options); metadata.appendImportOptionMetadata(options);
} }

View File

@ -45,7 +45,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang.exception.ExceptionUtils;
import org.json.JSONException;
import org.odftoolkit.odfdom.doc.OdfDocument; import org.odftoolkit.odfdom.doc.OdfDocument;
import org.odftoolkit.odfdom.doc.table.OdfTable; import org.odftoolkit.odfdom.doc.table.OdfTable;
import org.odftoolkit.odfdom.doc.table.OdfTableCell; import org.odftoolkit.odfdom.doc.table.OdfTableCell;
@ -146,14 +145,10 @@ public class OdsImporter extends TabularImportingParserBase {
ArrayNode sheets = JSONUtilities.getArray(options, "sheets"); ArrayNode sheets = JSONUtilities.getArray(options, "sheets");
for(int i=0;i<sheets.size();i++) { for(int i=0;i<sheets.size();i++) {
String[] fileNameAndSheetIndex = new String[2]; String[] fileNameAndSheetIndex = new String[2];
try { ObjectNode sheetObj = JSONUtilities.getObjectElement(sheets, i);
ObjectNode sheetObj = JSONUtilities.getObjectElement(sheets, i); // value is fileName#sheetIndex
// value is fileName#sheetIndex fileNameAndSheetIndex = sheetObj.get("fileNameAndSheetIndex").asText().split("#");
fileNameAndSheetIndex = sheetObj.get("fileNameAndSheetIndex").asText().split("#");
} catch (JSONException e) {
logger.error(ExceptionUtils.getFullStackTrace(e));
}
if (!fileNameAndSheetIndex[0].equals(fileSource)) if (!fileNameAndSheetIndex[0].equals(fileSource))
continue; continue;

View File

@ -50,7 +50,6 @@ import java.util.zip.GZIPOutputStream;
import org.apache.tools.tar.TarEntry; import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream; import org.apache.tools.tar.TarInputStream;
import org.apache.tools.tar.TarOutputStream; import org.apache.tools.tar.TarOutputStream;
import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -296,7 +295,7 @@ public class FileProjectManager extends ProjectManager {
return projectSaveNeeded || _preferenceStore.isDirty(); return projectSaveNeeded || _preferenceStore.isDirty();
} }
protected void saveProjectMetadata() throws JSONException, IOException { protected void saveProjectMetadata() throws IOException {
for(Entry<Long,ProjectMetadata> entry : _projectsMetadata.entrySet()) { for(Entry<Long,ProjectMetadata> entry : _projectsMetadata.entrySet()) {
ProjectMetadata metadata = entry.getValue(); ProjectMetadata metadata = entry.getValue();
if (metadata != null && metadata.isDirty()) { if (metadata != null && metadata.isDirty()) {
@ -305,7 +304,7 @@ public class FileProjectManager extends ProjectManager {
} }
} }
protected boolean saveToFile(File file) throws IOException, JSONException { protected boolean saveToFile(File file) throws IOException {
FileWriter writer = new FileWriter(file); FileWriter writer = new FileWriter(file);
boolean saveWasNeeded = saveNeeded(); boolean saveWasNeeded = saveNeeded();
try { try {

View File

@ -46,10 +46,6 @@ import java.util.List;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.json.JSONWriter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -61,7 +57,7 @@ import com.google.refine.util.ParsingUtilities;
public class ProjectMetadataUtilities { public class ProjectMetadataUtilities {
final static Logger logger = LoggerFactory.getLogger("project_metadata_utilities"); final static Logger logger = LoggerFactory.getLogger("project_metadata_utilities");
public static void save(ProjectMetadata projectMeta, File projectDir) throws JSONException, IOException { public static void save(ProjectMetadata projectMeta, File projectDir) throws IOException {
File tempFile = new File(projectDir, "metadata.temp.json"); File tempFile = new File(projectDir, "metadata.temp.json");
saveToFile(projectMeta, tempFile); saveToFile(projectMeta, tempFile);
@ -79,7 +75,7 @@ public class ProjectMetadataUtilities {
tempFile.renameTo(file); tempFile.renameTo(file);
} }
protected static void saveToFile(ProjectMetadata projectMeta, File metadataFile) throws JSONException, IOException { protected static void saveToFile(ProjectMetadata projectMeta, File metadataFile) throws IOException {
Writer writer = new OutputStreamWriter(new FileOutputStream(metadataFile)); Writer writer = new OutputStreamWriter(new FileOutputStream(metadataFile));
try { try {
ParsingUtilities.defaultWriter.writeValue(writer, projectMeta); ParsingUtilities.defaultWriter.writeValue(writer, projectMeta);

View File

@ -45,8 +45,6 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.json.JSONException;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
@ -224,7 +222,7 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat
Evaluable eval, Evaluable eval,
String description, String description,
boolean cacheResponses boolean cacheResponses
) throws JSONException { ) {
super(description); super(description);
_project = project; _project = project;
_engine = engine; _engine = engine;

View File

@ -41,8 +41,6 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.json.JSONException;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.browsing.Engine; import com.google.refine.browsing.Engine;
@ -140,7 +138,7 @@ public class ExtendDataOperation extends EngineDependentOperation {
Project project, Project project,
EngineConfig engineConfig, EngineConfig engineConfig,
String description String description
) throws JSONException { ) {
super(description); super(description);
_project = project; _project = project;
_engineConfig = engineConfig; _engineConfig = engineConfig;

View File

@ -35,8 +35,6 @@ package com.google.refine.sorting;
import java.util.List; import java.util.List;
import org.json.JSONException;
import com.google.refine.expr.EvalError; import com.google.refine.expr.EvalError;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.sorting.Criterion.KeyMaker; import com.google.refine.sorting.Criterion.KeyMaker;
@ -102,7 +100,7 @@ abstract public class BaseSorter {
} }
} }
public void initializeFromConfig(Project project, SortingConfig config) throws JSONException { public void initializeFromConfig(Project project, SortingConfig config) {
_criteria = config.getCriteria(); _criteria = config.getCriteria();
int count = _criteria.length; int count = _criteria.length;
_keyMakers = new KeyMaker[count]; _keyMakers = new KeyMaker[count];