From 3292052d5895589a9a426db4a0a05dd0e1b2bc07 Mon Sep 17 00:00:00 2001 From: Subhash Chandran Date: Wed, 15 Jan 2025 12:41:04 +0530 Subject: [PATCH] NPE handled for empty URL string --- lib/src/main/java/org/wiztools/restclient/util/Url.java | 3 +++ .../main/java/org/wiztools/restclient/ui/RESTViewImpl.java | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/org/wiztools/restclient/util/Url.java b/lib/src/main/java/org/wiztools/restclient/util/Url.java index 82b0cdce..3a63ae01 100644 --- a/lib/src/main/java/org/wiztools/restclient/util/Url.java +++ b/lib/src/main/java/org/wiztools/restclient/util/Url.java @@ -5,6 +5,9 @@ public class Url { public static java.net.URL get(String spec) throws MalformedURLException { + if(spec == null || spec.trim().isEmpty()) { + throw new MalformedURLException("URL is empty"); + } try { return new java.net.URI(spec).toURL(); } catch(URISyntaxException ex) { diff --git a/ui/src/main/java/org/wiztools/restclient/ui/RESTViewImpl.java b/ui/src/main/java/org/wiztools/restclient/ui/RESTViewImpl.java index 98b423c6..a3506cf7 100755 --- a/ui/src/main/java/org/wiztools/restclient/ui/RESTViewImpl.java +++ b/ui/src/main/java/org/wiztools/restclient/ui/RESTViewImpl.java @@ -8,7 +8,6 @@ import java.io.File; import java.net.HttpCookie; import java.net.MalformedURLException; -import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -26,6 +25,7 @@ import org.wiztools.restclient.IGlobalOptions; import org.wiztools.restclient.ServiceLocator; import org.wiztools.restclient.bean.*; +import org.wiztools.restclient.util.Url; import org.wiztools.restclient.ui.dnd.FileDropTargetListener; import org.wiztools.restclient.ui.history.HistoryManager; import org.wiztools.restclient.ui.reqauth.ReqAuthPanel; @@ -254,8 +254,11 @@ public Request getRequestFromUI() throws IllegalStateException { request.setAuth(auth); String url = jp_url_go.getUrlString(); + if(url == null || url.isEmpty()) { + throw new IllegalStateException("URL is empty"); + } try{ - request.setUrl(org.wiztools.restclient.util.Url.get(url)); + request.setUrl(Url.get(url)); } catch(MalformedURLException ex){ throw new IllegalStateException("URL is malformed", ex);