Throw IllegalArgumentException when url is null in LinkHandlerFactory

This commit is contained in:
TobiGr 2020-01-20 21:25:16 +01:00
parent 39de55dcd3
commit 7943130307
1 changed files with 6 additions and 5 deletions

View File

@ -34,7 +34,7 @@ public abstract class LinkHandlerFactory {
public abstract String getUrl(String id) throws ParsingException;
public abstract boolean onAcceptUrl(final String url) throws ParsingException;
public String getUrl(String id, String baseUrl) throws ParsingException{
public String getUrl(String id, String baseUrl) throws ParsingException {
return getUrl(id);
}
@ -43,13 +43,14 @@ public abstract class LinkHandlerFactory {
///////////////////////////////////
public LinkHandler fromUrl(String url) throws ParsingException {
if (url == null) throw new IllegalArgumentException("url can not be null");
final String baseUrl = Utils.getBaseUrl(url);
return fromUrl(url, baseUrl);
}
public LinkHandler fromUrl(String url, String baseUrl) throws ParsingException {
if(url == null) throw new IllegalArgumentException("url can not be null");
if(!acceptUrl(url)) {
if (url == null) throw new IllegalArgumentException("url can not be null");
if (!acceptUrl(url)) {
throw new ParsingException("Malformed unacceptable url: " + url);
}
@ -58,13 +59,13 @@ public abstract class LinkHandlerFactory {
}
public LinkHandler fromId(String id) throws ParsingException {
if(id == null) throw new IllegalArgumentException("id can not be null");
if (id == null) throw new IllegalArgumentException("id can not be null");
final String url = getUrl(id);
return new LinkHandler(url, url, id);
}
public LinkHandler fromId(String id, String baseUrl) throws ParsingException {
if(id == null) throw new IllegalArgumentException("id can not be null");
if (id == null) throw new IllegalArgumentException("id can not be null");
final String url = getUrl(id, baseUrl);
return new LinkHandler(url, url, id);
}