Skip to content

Commit 4a4939d

Browse files
authored
Merge pull request TeamNewPipe#877 from Isira-Seneviratne/Use_Objects_requireNonNull
Use Objects.requireNonNull().
2 parents c336bd5 + 682a426 commit 4a4939d

File tree

3 files changed

+9
-22
lines changed

3 files changed

+9
-22
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/downloader/Request.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,8 @@ public Request(final String httpMethod,
3232
@Nullable final byte[] dataToSend,
3333
@Nullable final Localization localization,
3434
final boolean automaticLocalizationHeader) {
35-
if (httpMethod == null) {
36-
throw new IllegalArgumentException("Request's httpMethod is null");
37-
}
38-
if (url == null) {
39-
throw new IllegalArgumentException("Request's url is null");
40-
}
41-
42-
this.httpMethod = httpMethod;
43-
this.url = url;
35+
this.httpMethod = Objects.requireNonNull(httpMethod, "Request's httpMethod is null");
36+
this.url = Objects.requireNonNull(url, "Request's url is null");
4437
this.dataToSend = dataToSend;
4538
this.localization = localization;
4639

extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/LinkHandlerFactory.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.schabi.newpipe.extractor.exceptions.ParsingException;
44
import org.schabi.newpipe.extractor.utils.Utils;
55

6+
import java.util.Objects;
7+
68
/*
79
* Created by Christian Schabesberger on 26.07.16.
810
*
@@ -72,9 +74,7 @@ public LinkHandler fromUrl(final String url) throws ParsingException {
7274
* @return a {@link LinkHandler} complete with information
7375
*/
7476
public LinkHandler fromUrl(final String url, final String baseUrl) throws ParsingException {
75-
if (url == null) {
76-
throw new IllegalArgumentException("URL cannot be null");
77-
}
77+
Objects.requireNonNull(url, "URL cannot be null");
7878
if (!acceptUrl(url)) {
7979
throw new ParsingException("URL not accepted: " + url);
8080
}
@@ -84,17 +84,13 @@ public LinkHandler fromUrl(final String url, final String baseUrl) throws Parsin
8484
}
8585

8686
public LinkHandler fromId(final String id) throws ParsingException {
87-
if (id == null) {
88-
throw new IllegalArgumentException("id can not be null");
89-
}
87+
Objects.requireNonNull(id, "ID cannot be null");
9088
final String url = getUrl(id);
9189
return new LinkHandler(url, url, id);
9290
}
9391

9492
public LinkHandler fromId(final String id, final String baseUrl) throws ParsingException {
95-
if (id == null) {
96-
throw new IllegalArgumentException("id can not be null");
97-
}
93+
Objects.requireNonNull(id, "ID cannot be null");
9894
final String url = getUrl(id, baseUrl);
9995
return new LinkHandler(url, url, id);
10096
}

extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/ListLinkHandlerFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.ArrayList;
77
import java.util.List;
8+
import java.util.Objects;
89

910
public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
1011

@@ -35,10 +36,7 @@ public ListLinkHandler fromUrl(final String url) throws ParsingException {
3536

3637
@Override
3738
public ListLinkHandler fromUrl(final String url, final String baseUrl) throws ParsingException {
38-
if (url == null) {
39-
throw new IllegalArgumentException("url may not be null");
40-
}
41-
39+
Objects.requireNonNull(url, "URL may not be null");
4240
return new ListLinkHandler(super.fromUrl(url, baseUrl));
4341
}
4442

0 commit comments

Comments
 (0)