Skip to content

Commit

Permalink
NPE handled for empty URL string
Browse files Browse the repository at this point in the history
  • Loading branch information
subwiz committed Jan 15, 2025
1 parent e4d2105 commit 3292052
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/src/main/java/org/wiztools/restclient/util/Url.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions ui/src/main/java/org/wiztools/restclient/ui/RESTViewImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3292052

Please sign in to comment.