From ded6ca07d1fb1f88f1b7f9bae7e1de6d3c22e311 Mon Sep 17 00:00:00 2001 From: Gomaa Date: Tue, 25 Aug 2020 20:40:49 +0200 Subject: [PATCH] Handle NumberFormatException thrown in DatabaseImportController (#3116) * Handle NumberFormatException thrown in DatabaseImportController * Update extensions/database/src/com/google/refine/extension/database/DatabaseImportController.java Co-authored-by: Antonin Delpeuch * Update DatabaseImportController.java Add space just before the catch block Co-authored-by: Antonin Delpeuch --- .../extension/database/DatabaseImportController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/database/src/com/google/refine/extension/database/DatabaseImportController.java b/extensions/database/src/com/google/refine/extension/database/DatabaseImportController.java index dc900ba82..1faa1cef8 100644 --- a/extensions/database/src/com/google/refine/extension/database/DatabaseImportController.java +++ b/extensions/database/src/com/google/refine/extension/database/DatabaseImportController.java @@ -450,7 +450,11 @@ public class DatabaseImportController implements ImportingController { jdbcConfig.setConnectionName(request.getParameter("connectionName")); jdbcConfig.setDatabaseType(request.getParameter("databaseType")); jdbcConfig.setDatabaseHost(request.getParameter("databaseServer")); - jdbcConfig.setDatabasePort(Integer.parseInt(request.getParameter("databasePort"))); + try { + jdbcConfig.setDatabasePort(Integer.parseInt(request.getParameter("databasePort"))); + } catch(NumberFormatException nfE) { + logger.error("getQueryInfo :: invalid database port ::{}", nfE); + } jdbcConfig.setDatabaseUser(request.getParameter("databaseUser")); jdbcConfig.setDatabasePassword(request.getParameter("databasePassword")); jdbcConfig.setDatabaseName(request.getParameter("initialDatabase")); @@ -462,7 +466,7 @@ public class DatabaseImportController implements ImportingController { } if (jdbcConfig.getDatabaseHost() == null || jdbcConfig.getDatabaseName() == null || jdbcConfig.getDatabasePassword() == null || jdbcConfig.getDatabaseType() == null - || jdbcConfig.getDatabaseUser() == null || query == null) { + || jdbcConfig.getDatabaseUser() == null || query == null || jdbcConfig.getDatabasePort() == 0) { if(logger.isDebugEnabled()) { logger.debug("Missing Database Configuration::{}", jdbcConfig); }