Skip to content

Commit 0d935f4

Browse files
committed
Explicitly check arguments for null
(Not using Objects.requireNonNull because it's not available on older Android.)
1 parent c1bcada commit 0d935f4

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/java/org/nibor/autolink/Autolink.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ public class Autolink {
99
* Render the supplied links from the supplied input text using a renderer. The parts of the text outside of links
1010
* are added to the result without processing.
1111
*
12-
* @param input the input text
12+
* @param input the input text, must not be null
1313
* @param links the links to render, see {@link LinkExtractor} to extract them
1414
* @param linkRenderer the link rendering implementation
1515
* @return the rendered string
1616
*/
1717
public static String renderLinks(CharSequence input, Iterable<LinkSpan> links, LinkRenderer linkRenderer) {
18+
if (input == null) {
19+
throw new NullPointerException("input must not be null");
20+
}
21+
if (links == null) {
22+
throw new NullPointerException("links must not be null");
23+
}
24+
if (linkRenderer == null) {
25+
throw new NullPointerException("linkRenderer must not be null");
26+
}
1827
StringBuilder sb = new StringBuilder(input.length() + 16);
1928
int lastIndex = 0;
2029
for (LinkSpan link : links) {

src/main/java/org/nibor/autolink/LinkExtractor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ public static Builder builder() {
3131
/**
3232
* Extract the links from the input text. Can be called multiple times with different inputs (thread-safe).
3333
*
34-
* @param input the input text, must not be {@code null}
35-
* @return a lazy iterable for the links in order that they appear in the input, never {@code null}
34+
* @param input the input text, must not be null
35+
* @return a lazy iterable for the links in order that they appear in the input, never null
3636
*/
3737
public Iterable<LinkSpan> extractLinks(final CharSequence input) {
38+
if (input == null) {
39+
throw new NullPointerException("input must not be null");
40+
}
3841
return new Iterable<LinkSpan>() {
3942
@Override
4043
public Iterator<LinkSpan> iterator() {

0 commit comments

Comments
 (0)