From f3518ec76f25a011f1cce670f8d66a4a0f9c2343 Mon Sep 17 00:00:00 2001 From: Chris Zhao Date: Tue, 15 Nov 2016 22:07:40 +0100 Subject: [PATCH] Add null-ptr-check on UrlDetector & InputTextReader --- url-detector/build.gradle | 6 ++++++ .../java/com/linkedin/urls/detection/InputTextReader.java | 7 ++++++- .../java/com/linkedin/urls/detection/UrlDetector.java | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/url-detector/build.gradle b/url-detector/build.gradle index 4242e0d..7588beb 100644 --- a/url-detector/build.gradle +++ b/url-detector/build.gradle @@ -1,3 +1,9 @@ apply plugin: 'java' apply plugin: 'idea' +dependencies { + sourceCompatibility = 1.7 + targetCompatibility = 1.7 + + compile 'org.apache.commons:commons-lang3:3.4' +} diff --git a/url-detector/src/main/java/com/linkedin/urls/detection/InputTextReader.java b/url-detector/src/main/java/com/linkedin/urls/detection/InputTextReader.java index c58e0ea..24f851b 100644 --- a/url-detector/src/main/java/com/linkedin/urls/detection/InputTextReader.java +++ b/url-detector/src/main/java/com/linkedin/urls/detection/InputTextReader.java @@ -42,8 +42,13 @@ public class InputTextReader { /** * Creates a new instance of the InputTextReader using the content to read. * @param content The content to read. + * @throws {@link NullPointerException} if {@code content == null} . */ - public InputTextReader(String content) { + public InputTextReader(String content) throws NullPointerException { + if (content == null) { + throw new NullPointerException("content must't be null."); + } + _content = content.toCharArray(); } diff --git a/url-detector/src/main/java/com/linkedin/urls/detection/UrlDetector.java b/url-detector/src/main/java/com/linkedin/urls/detection/UrlDetector.java index 43815f6..1514453 100644 --- a/url-detector/src/main/java/com/linkedin/urls/detection/UrlDetector.java +++ b/url-detector/src/main/java/com/linkedin/urls/detection/UrlDetector.java @@ -12,6 +12,7 @@ import com.linkedin.urls.Url; import com.linkedin.urls.UrlMarker; import com.linkedin.urls.UrlPart; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -119,8 +120,13 @@ public enum ReadEndState { * Creates a new UrlDetector object used to find urls inside of text. * @param content The content to search inside of. * @param options The UrlDetectorOptions to use when detecting the content. + * @throws {@link NullPointerException} if {@code content == null} . */ - public UrlDetector(String content, UrlDetectorOptions options) { + public UrlDetector(String content, UrlDetectorOptions options) throws NullPointerException { + if (content == null) { + throw new NullPointerException("content must't be null."); + } + _reader = new InputTextReader(content); _options = options; }