diff --git a/build.gradle.kts b/build.gradle.kts
index c5de688..505c00e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -28,7 +28,7 @@ plugins {
alias(libs.plugins.versions)
}
-version = ProjectVersion("1.0.1", BuildType.snapshot)
+version = ProjectVersion("2.0.0", BuildType.snapshot)
group = "org.cthing"
description = "A Java library for escaping strings for use in various languages (e.g. XML)."
@@ -39,9 +39,9 @@ java {
}
dependencies {
- api(libs.jsr305)
+ api(libs.jspecify)
- implementation(libs.cthingAnnots)
+ compileOnly(libs.cthingAnnots)
testImplementation(libs.junitApi)
testImplementation(libs.junitParams)
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 882dba6..8a79650 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -13,8 +13,8 @@ versions = { id = "com.github.ben-manes.versions", version = "0.51.0" }
[libraries]
assertJ = "org.assertj:assertj-core:3.26.3"
-cthingAnnots = "org.cthing:cthing-annotations:1.0.0"
-jsr305 = "com.google.code.findbugs:jsr305:3.0.2"
+cthingAnnots = "org.cthing:cthing-annotations:2.0.0"
+jspecify = "org.jspecify:jspecify:1.0.0"
junitApi = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junitEngine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junitLauncher = "org.junit.platform:junit-platform-launcher:1.11.2"
diff --git a/src/main/java/org/cthing/escapers/CsvEscaper.java b/src/main/java/org/cthing/escapers/CsvEscaper.java
index c1615f5..ebdc386 100644
--- a/src/main/java/org/cthing/escapers/CsvEscaper.java
+++ b/src/main/java/org/cthing/escapers/CsvEscaper.java
@@ -10,9 +10,8 @@
import java.io.UncheckedIOException;
import java.io.Writer;
-import javax.annotation.WillNotClose;
-
import org.cthing.annotations.NoCoverageGenerated;
+import org.jspecify.annotations.Nullable;
/**
@@ -34,7 +33,8 @@ private CsvEscaper() {
* @param charSequence String to escape
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence) {
return (charSequence == null)
? null : escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length());
}
@@ -43,12 +43,11 @@ public static String escape(final CharSequence charSequence) {
* Applies CSV escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer) throws IOException {
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer) throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer);
}
@@ -60,7 +59,8 @@ public static void escape(final CharSequence charSequence, final Writer writer)
* @param charArr Character array to escape
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr) {
return (charArr == null) ? null : escape(index -> Character.codePointAt(charArr, index), 0, charArr.length);
}
@@ -72,7 +72,8 @@ public static String escape(final char[] charArr) {
* @param length Number of characters in array
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final int offset, final int length) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length) {
return (charArr == null) ? null : escape(index -> Character.codePointAt(charArr, index), offset, length);
}
@@ -80,12 +81,11 @@ public static String escape(final char[] charArr, final int offset, final int le
* Applies CSV escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer);
}
@@ -97,12 +97,11 @@ public static void escape(final char[] charArr, final Writer writer) throws IOEx
* @param charArr Character array to escape
* @param offset Start index in array
* @param length Number of characters in array
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final int offset, final int length, final Writer writer)
+ public static void escape(final char @Nullable[] charArr, final int offset, final int length, final Writer writer)
throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer);
@@ -120,11 +119,7 @@ private static String escape(final CodePointProvider codePointProvider, final in
}
private static void escape(final CodePointProvider codePointProvider, final int offset, final int length,
- final Writer writer)
- throws IOException {
- if (writer == null) {
- throw new IllegalArgumentException("writer must not be null");
- }
+ final Writer writer) throws IOException {
if (length < 0) {
throw new IndexOutOfBoundsException("length must be greater than or equal to 0");
}
diff --git a/src/main/java/org/cthing/escapers/HtmlEscaper.java b/src/main/java/org/cthing/escapers/HtmlEscaper.java
index 7b315a5..ee87ffc 100644
--- a/src/main/java/org/cthing/escapers/HtmlEscaper.java
+++ b/src/main/java/org/cthing/escapers/HtmlEscaper.java
@@ -12,9 +12,8 @@
import java.util.Set;
import java.util.function.Function;
-import javax.annotation.WillNotClose;
-
import org.cthing.annotations.NoCoverageGenerated;
+import org.jspecify.annotations.Nullable;
/**
@@ -207,7 +206,8 @@ private HtmlEscaper() {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Option... options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Option... options) {
return (charSequence == null)
? null
: escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(),
@@ -221,7 +221,8 @@ public static String escape(final CharSequence charSequence, final Option... opt
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Set options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Set options) {
return (charSequence == null)
? null : escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), options);
}
@@ -230,13 +231,12 @@ public static String escape(final CharSequence charSequence, final Set o
* Applies HTML escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Option... options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Option... options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer,
@@ -248,13 +248,12 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* Applies HTML escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Set options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Set options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer, options);
@@ -268,7 +267,8 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), 0, charArr.length,
@@ -284,7 +284,9 @@ public static String escape(final char[] charArr, final Option... options) {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), offset, length,
@@ -298,7 +300,8 @@ public static String escape(final char[] charArr, final int offset, final int le
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Set options) {
return (charArr == null)
? null : escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, options);
}
@@ -312,7 +315,9 @@ public static String escape(final char[] charArr, final Set options) {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Set options) {
return (charArr == null)
? null : escape(index -> Character.codePointAt(charArr, index), offset, length, options);
}
@@ -321,13 +326,13 @@ public static String escape(final char[] charArr, final int offset, final int le
* Applies HTML escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Option... options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Option... options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer,
toEnumSet(HtmlEscaper.Option.class, options));
@@ -340,13 +345,12 @@ public static void escape(final char[] charArr, final Writer writer, final Optio
* @param charArr Character array to escape
* @param offset Start index in array
* @param length Number of characters in array
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final int offset, final int length, final Writer writer,
+ public static void escape(final char @Nullable[] charArr, final int offset, final int length, final Writer writer,
final Option... options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer,
@@ -358,13 +362,13 @@ public static void escape(final char[] charArr, final int offset, final int leng
* Applies HTML escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Set options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer, options);
}
@@ -376,13 +380,12 @@ public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer, options);
@@ -402,9 +405,6 @@ private static String escape(final CodePointProvider codePointProvider, final in
private static void escape(final CodePointProvider codePointProvider, final int offset, final int length,
final Writer writer, final Set options) throws IOException {
- if (writer == null) {
- throw new IllegalArgumentException("writer must not be null");
- }
if (length < 0) {
throw new IndexOutOfBoundsException("length must be greater than or equal to 0");
}
@@ -415,7 +415,7 @@ private static void escape(final CodePointProvider codePointProvider, final int
final boolean useLatin1 = options.contains(Option.USE_ISO_LATIN_1_ENTITIES);
final boolean useExtended = options.contains(Option.USE_HTML4_EXTENDED_ENTITIES);
- final Function findEntity;
+ final Function findEntity;
if (!useLatin1 && !useExtended) {
findEntity = HtmlEntities.MARKUP_SIGNIFICANT::get;
} else {
diff --git a/src/main/java/org/cthing/escapers/JavaEscaper.java b/src/main/java/org/cthing/escapers/JavaEscaper.java
index 05e9880..7ff8817 100644
--- a/src/main/java/org/cthing/escapers/JavaEscaper.java
+++ b/src/main/java/org/cthing/escapers/JavaEscaper.java
@@ -11,9 +11,8 @@
import java.io.Writer;
import java.util.Set;
-import javax.annotation.WillNotClose;
-
import org.cthing.annotations.NoCoverageGenerated;
+import org.jspecify.annotations.Nullable;
/**
@@ -151,7 +150,8 @@ private JavaEscaper() {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Option... options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Option... options) {
return (charSequence == null)
? null
: escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(),
@@ -165,7 +165,8 @@ public static String escape(final CharSequence charSequence, final Option... opt
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Set options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Set options) {
return (charSequence == null)
? null
: escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), options);
@@ -175,13 +176,12 @@ public static String escape(final CharSequence charSequence, final Set o
* Applies JSON escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Option... options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Option... options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer,
@@ -193,13 +193,12 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* Applies JSON escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Set options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Set options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer, options);
@@ -213,7 +212,8 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), 0, charArr.length,
@@ -229,7 +229,9 @@ public static String escape(final char[] charArr, final Option... options) {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), offset, length,
@@ -243,7 +245,8 @@ public static String escape(final char[] charArr, final int offset, final int le
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Set options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, options);
@@ -258,7 +261,9 @@ public static String escape(final char[] charArr, final Set options) {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Set options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), offset, length, options);
@@ -268,13 +273,13 @@ public static String escape(final char[] charArr, final int offset, final int le
* Applies JSON escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Option... options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Option... options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer,
toEnumSet(JavaEscaper.Option.class, options));
@@ -287,13 +292,12 @@ public static void escape(final char[] charArr, final Writer writer, final Optio
* @param charArr Character array to escape
* @param offset Start index in array
* @param length Number of characters in array
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final int offset, final int length, final Writer writer,
+ public static void escape(final char @Nullable[] charArr, final int offset, final int length, final Writer writer,
final Option... options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer,
@@ -305,13 +309,13 @@ public static void escape(final char[] charArr, final int offset, final int leng
* Applies JSON escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Set options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer, options);
}
@@ -323,13 +327,12 @@ public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer, options);
@@ -349,9 +352,6 @@ private static String escape(final CodePointProvider codePointProvider, final in
private static void escape(final CodePointProvider codePointProvider, final int offset, final int length,
final Writer writer, final Set options) throws IOException {
- if (writer == null) {
- throw new IllegalArgumentException("writer must not be null");
- }
if (length < 0) {
throw new IndexOutOfBoundsException("length must be greater than or equal to 0");
}
diff --git a/src/main/java/org/cthing/escapers/JavaScriptEscaper.java b/src/main/java/org/cthing/escapers/JavaScriptEscaper.java
index 908708f..6e0fade 100644
--- a/src/main/java/org/cthing/escapers/JavaScriptEscaper.java
+++ b/src/main/java/org/cthing/escapers/JavaScriptEscaper.java
@@ -11,9 +11,8 @@
import java.io.Writer;
import java.util.Set;
-import javax.annotation.WillNotClose;
-
import org.cthing.annotations.NoCoverageGenerated;
+import org.jspecify.annotations.Nullable;
/**
@@ -154,7 +153,8 @@ private JavaScriptEscaper() {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Option... options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Option... options) {
return (charSequence == null)
? null
: escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(),
@@ -168,7 +168,8 @@ public static String escape(final CharSequence charSequence, final Option... opt
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Set options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Set options) {
return (charSequence == null)
? null
: escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), options);
@@ -178,13 +179,12 @@ public static String escape(final CharSequence charSequence, final Set o
* Applies JavaScript escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Option... options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Option... options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer,
@@ -196,13 +196,12 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* Applies JavaScript escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Set options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Set options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer, options);
@@ -216,7 +215,8 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), 0, charArr.length,
@@ -232,7 +232,9 @@ public static String escape(final char[] charArr, final Option... options) {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), offset, length,
@@ -246,7 +248,8 @@ public static String escape(final char[] charArr, final int offset, final int le
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Set options) {
return (charArr == null)
? null : escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, options);
}
@@ -260,7 +263,9 @@ public static String escape(final char[] charArr, final Set options) {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Set options) {
return (charArr == null)
? null : escape(index -> Character.codePointAt(charArr, index), offset, length, options);
}
@@ -269,13 +274,13 @@ public static String escape(final char[] charArr, final int offset, final int le
* Applies JavaScript escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Option... options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Option... options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer,
toEnumSet(JavaScriptEscaper.Option.class, options));
@@ -288,13 +293,12 @@ public static void escape(final char[] charArr, final Writer writer, final Optio
* @param charArr Character array to escape
* @param offset Start index in array
* @param length Number of characters in array
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final int offset, final int length, final Writer writer,
+ public static void escape(final char @Nullable[] charArr, final int offset, final int length, final Writer writer,
final Option... options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer,
@@ -306,13 +310,13 @@ public static void escape(final char[] charArr, final int offset, final int leng
* Applies JavaScript escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Set options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer, options);
}
@@ -324,13 +328,12 @@ public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer, options);
@@ -350,9 +353,6 @@ private static String escape(final CodePointProvider codePointProvider, final in
private static void escape(final CodePointProvider codePointProvider, final int offset, final int length,
final Writer writer, final Set options) throws IOException {
- if (writer == null) {
- throw new IllegalArgumentException("writer must not be null");
- }
if (length < 0) {
throw new IndexOutOfBoundsException("length must be greater than or equal to 0");
}
diff --git a/src/main/java/org/cthing/escapers/JsonEscaper.java b/src/main/java/org/cthing/escapers/JsonEscaper.java
index a4d16b1..78f12d6 100644
--- a/src/main/java/org/cthing/escapers/JsonEscaper.java
+++ b/src/main/java/org/cthing/escapers/JsonEscaper.java
@@ -11,9 +11,8 @@
import java.io.Writer;
import java.util.Set;
-import javax.annotation.WillNotClose;
-
import org.cthing.annotations.NoCoverageGenerated;
+import org.jspecify.annotations.Nullable;
/**
@@ -144,7 +143,8 @@ private JsonEscaper() {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Option... options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Option... options) {
return (charSequence == null)
? null
: escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(),
@@ -158,7 +158,8 @@ public static String escape(final CharSequence charSequence, final Option... opt
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Set options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Set options) {
return (charSequence == null)
? null
: escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), options);
@@ -168,13 +169,12 @@ public static String escape(final CharSequence charSequence, final Set o
* Applies JSON escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Option... options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Option... options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer,
@@ -186,13 +186,12 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* Applies JSON escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Set options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Set options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer, options);
@@ -206,7 +205,8 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), 0, charArr.length,
@@ -222,7 +222,9 @@ public static String escape(final char[] charArr, final Option... options) {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), offset, length,
@@ -236,7 +238,8 @@ public static String escape(final char[] charArr, final int offset, final int le
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Set options) {
return (charArr == null)
? null : escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, options);
}
@@ -250,7 +253,9 @@ public static String escape(final char[] charArr, final Set options) {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Set options) {
return (charArr == null)
? null : escape(index -> Character.codePointAt(charArr, index), offset, length, options);
}
@@ -259,13 +264,13 @@ public static String escape(final char[] charArr, final int offset, final int le
* Applies JSON escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Option... options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Option... options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer,
toEnumSet(JsonEscaper.Option.class, options));
@@ -278,13 +283,12 @@ public static void escape(final char[] charArr, final Writer writer, final Optio
* @param charArr Character array to escape
* @param offset Start index in array
* @param length Number of characters in array
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final int offset, final int length, final Writer writer,
+ public static void escape(final char @Nullable[] charArr, final int offset, final int length, final Writer writer,
final Option... options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer,
@@ -296,13 +300,13 @@ public static void escape(final char[] charArr, final int offset, final int leng
* Applies JSON escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Set options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer, options);
}
@@ -314,13 +318,12 @@ public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer, options);
@@ -340,9 +343,6 @@ private static String escape(final CodePointProvider codePointProvider, final in
private static void escape(final CodePointProvider codePointProvider, final int offset, final int length,
final Writer writer, final Set options) throws IOException {
- if (writer == null) {
- throw new IllegalArgumentException("writer must not be null");
- }
if (length < 0) {
throw new IndexOutOfBoundsException("length must be greater than or equal to 0");
}
diff --git a/src/main/java/org/cthing/escapers/XmlEscaper.java b/src/main/java/org/cthing/escapers/XmlEscaper.java
index 6f955c4..7480a68 100644
--- a/src/main/java/org/cthing/escapers/XmlEscaper.java
+++ b/src/main/java/org/cthing/escapers/XmlEscaper.java
@@ -11,9 +11,8 @@
import java.io.Writer;
import java.util.Set;
-import javax.annotation.WillNotClose;
-
import org.cthing.annotations.NoCoverageGenerated;
+import org.jspecify.annotations.Nullable;
/**
@@ -180,7 +179,8 @@ private XmlEscaper() {
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final CharSequence charSequence, final Option... options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Option... options) {
return (charSequence == null)
? null
: escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(),
@@ -195,7 +195,8 @@ public static String escape(final CharSequence charSequence, final Option... opt
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final CharSequence charSequence, final Set options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Set options) {
return (charSequence == null)
? null
: escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), options);
@@ -206,13 +207,12 @@ public static String escape(final CharSequence charSequence, final Set o
* invalid XML characters are not included in the output.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Option... options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Option... options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer,
@@ -225,13 +225,12 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* invalid XML characters are not included in the output.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Set options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Set options)
throws IOException {
if (charSequence != null) {
escape(index -> Character.codePointAt(charSequence, index), 0, charSequence.length(), writer, options);
@@ -246,7 +245,8 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final char[] charArr, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), 0, charArr.length,
@@ -263,7 +263,9 @@ public static String escape(final char[] charArr, final Option... options) {
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Option... options) {
return (charArr == null)
? null
: escape(index -> Character.codePointAt(charArr, index), offset, length,
@@ -278,7 +280,8 @@ public static String escape(final char[] charArr, final int offset, final int le
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final char[] charArr, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Set options) {
return (charArr == null)
? null : escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, options);
}
@@ -293,7 +296,9 @@ public static String escape(final char[] charArr, final Set options) {
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Set options) {
return (charArr == null)
? null : escape(index -> Character.codePointAt(charArr, index), offset, length, options);
}
@@ -303,13 +308,13 @@ public static String escape(final char[] charArr, final int offset, final int le
* invalid XML characters are not included in the output.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Option... options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Option... options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer,
toEnumSet(XmlEscaper.Option.class, options));
@@ -323,13 +328,12 @@ public static void escape(final char[] charArr, final Writer writer, final Optio
* @param charArr Character array to escape
* @param offset Start index in array
* @param length Number of characters in array
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final int offset, final int length, final Writer writer,
+ public static void escape(final char @Nullable[] charArr, final int offset, final int length, final Writer writer,
final Option... options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer,
@@ -342,13 +346,13 @@ public static void escape(final char[] charArr, final int offset, final int leng
* invalid XML characters are not included in the output.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Set options)
+ throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), 0, charArr.length, writer, options);
}
@@ -361,13 +365,12 @@ public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
if (charArr != null) {
escape(index -> Character.codePointAt(charArr, index), offset, length, writer, options);
@@ -387,9 +390,6 @@ private static String escape(final CodePointProvider codePointProvider, final in
private static void escape(final CodePointProvider codePointProvider, final int offset, final int length,
final Writer writer, final Set options) throws IOException {
- if (writer == null) {
- throw new IllegalArgumentException("writer must not be null");
- }
if (length < 0) {
throw new IndexOutOfBoundsException("length must be greater than or equal to 0");
}
diff --git a/src/main/java/org/cthing/escapers/YamlEscaper.java b/src/main/java/org/cthing/escapers/YamlEscaper.java
index 6cc1a19..7ad68ab 100644
--- a/src/main/java/org/cthing/escapers/YamlEscaper.java
+++ b/src/main/java/org/cthing/escapers/YamlEscaper.java
@@ -11,10 +11,9 @@
import java.io.Writer;
import java.util.Set;
-import javax.annotation.WillNotClose;
-
import org.cthing.annotations.AccessForTesting;
import org.cthing.annotations.NoCoverageGenerated;
+import org.jspecify.annotations.Nullable;
/**
@@ -235,7 +234,8 @@ private YamlEscaper() {
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Option... options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Option... options) {
return (charSequence == null)
? null : escape(charSequence.toString(), toEnumSet(YamlEscaper.Option.class, options));
}
@@ -247,7 +247,8 @@ public static String escape(final CharSequence charSequence, final Option... opt
* @param options Escaping options
* @return Escaped string or {@code null} if {@code null} was passed in.
*/
- public static String escape(final CharSequence charSequence, final Set options) {
+ @Nullable
+ public static String escape(@Nullable final CharSequence charSequence, final Set options) {
return (charSequence == null) ? null : escape(charSequence.toString(), options);
}
@@ -255,13 +256,12 @@ public static String escape(final CharSequence charSequence, final Set o
* Applies YAML escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Option... options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Option... options)
throws IOException {
if (charSequence != null) {
escape(charSequence.toString(), writer, toEnumSet(YamlEscaper.Option.class, options));
@@ -272,13 +272,12 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* Applies YAML escaping to the specified string and writes the result to the specified writer.
*
* @param charSequence String to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final CharSequence charSequence, final Writer writer, final Set options)
+ public static void escape(@Nullable final CharSequence charSequence, final Writer writer, final Set options)
throws IOException {
if (charSequence != null) {
escape(charSequence.toString(), writer, options);
@@ -293,7 +292,8 @@ public static void escape(final CharSequence charSequence, final Writer writer,
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final char[] charArr, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Option... options) {
return (charArr == null) ? null : escape(new String(charArr), toEnumSet(YamlEscaper.Option.class, options));
}
@@ -307,7 +307,9 @@ public static String escape(final char[] charArr, final Option... options) {
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Option... options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Option... options) {
return (charArr == null) ? null : escape(new String(charArr, offset, length),
toEnumSet(YamlEscaper.Option.class, options));
}
@@ -320,7 +322,8 @@ public static String escape(final char[] charArr, final int offset, final int le
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final char[] charArr, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final Set options) {
return (charArr == null) ? null : escape(new String(charArr), options);
}
@@ -334,7 +337,9 @@ public static String escape(final char[] charArr, final Set options) {
* @return Escaped string or {@code null} if {@code null} was passed in. Note that invalid XML characters are
* not included in the output.
*/
- public static String escape(final char[] charArr, final int offset, final int length, final Set options) {
+ @Nullable
+ public static String escape(final char @Nullable[] charArr, final int offset, final int length,
+ final Set options) {
return (charArr == null) ? null : escape(new String(charArr, offset, length), options);
}
@@ -342,13 +347,13 @@ public static String escape(final char[] charArr, final int offset, final int le
* Applies YAML escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Option... options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Option... options)
+ throws IOException {
if (charArr != null) {
escape(new String(charArr), writer, toEnumSet(YamlEscaper.Option.class, options));
}
@@ -360,13 +365,12 @@ public static void escape(final char[] charArr, final Writer writer, final Optio
* @param charArr Character array to escape
* @param offset Start index in array
* @param length Number of characters in array
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final int offset, final int length, final Writer writer,
+ public static void escape(final char @Nullable[] charArr, final int offset, final int length, final Writer writer,
final Option... options) throws IOException {
if (charArr != null) {
escape(new String(charArr, offset, length), writer, toEnumSet(YamlEscaper.Option.class, options));
@@ -377,13 +381,13 @@ public static void escape(final char[] charArr, final int offset, final int leng
* Applies YAML escaping to the specified character array and writes the result to the specified writer.
*
* @param charArr Character array to escape
- * @param writer Writer to which the escaped string is written
+ * @param writer Writer to which the escaped string is written. Will not be closed by this method.
* @param options Escaping options
* @throws IOException if there was a problem writing the escaped string
* @throws IllegalArgumentException if the writer is {@code null}
*/
- @WillNotClose
- public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
+ public static void escape(final char @Nullable[] charArr, final Writer writer, final Set options)
+ throws IOException {
if (charArr != null) {
escape(new String(charArr), writer, options);
}
@@ -394,13 +398,12 @@ public static void escape(final char[] charArr, final Writer writer, final Set options) throws IOException {
if (charArr != null) {
escape(new String(charArr, offset, length), writer, options);
@@ -417,12 +420,7 @@ private static String escape(final String str, final Set options) {
}
}
- private static void escape(final String str, final Writer writer, final Set options)
- throws IOException {
- if (writer == null) {
- throw new IllegalArgumentException("writer must not be null");
- }
-
+ private static void escape(final String str, final Writer writer, final Set options) throws IOException {
final boolean escapeNonAscii = options.contains(Option.ESCAPE_NON_ASCII);
final Quoting quoting = requiresQuotes(str, escapeNonAscii);
diff --git a/src/main/java/org/cthing/escapers/package-info.java b/src/main/java/org/cthing/escapers/package-info.java
index 8ff725b..454ed1e 100644
--- a/src/main/java/org/cthing/escapers/package-info.java
+++ b/src/main/java/org/cthing/escapers/package-info.java
@@ -15,4 +15,7 @@
* YAML
*
*/
+@NullMarked
package org.cthing.escapers;
+
+import org.jspecify.annotations.NullMarked;
diff --git a/src/test/java/org/cthing/escapers/CsvEscaperTest.java b/src/test/java/org/cthing/escapers/CsvEscaperTest.java
index 67c63f6..c3c889e 100644
--- a/src/test/java/org/cthing/escapers/CsvEscaperTest.java
+++ b/src/test/java/org/cthing/escapers/CsvEscaperTest.java
@@ -15,7 +15,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIndexOutOfBoundsException;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -71,9 +70,6 @@ public void testErrors() throws IOException {
CsvEscaper.escape((char[])null, writer);
assertThat(writer.toString()).isEmpty();
- assertThatIllegalArgumentException().isThrownBy(() -> CsvEscaper.escape("hello", null));
- assertThatIllegalArgumentException().isThrownBy(() -> CsvEscaper.escape("hello".toCharArray(), null));
-
assertThatIndexOutOfBoundsException().isThrownBy(() -> CsvEscaper.escape("hello".toCharArray(), -1, 3));
assertThatIndexOutOfBoundsException().isThrownBy(() -> CsvEscaper.escape("hello".toCharArray(), 0, 20));
assertThatIndexOutOfBoundsException().isThrownBy(() -> CsvEscaper.escape("hello".toCharArray(), 0, -1));
diff --git a/src/test/java/org/cthing/escapers/HtmlEscaperTest.java b/src/test/java/org/cthing/escapers/HtmlEscaperTest.java
index 3eca1e9..8b30d5d 100644
--- a/src/test/java/org/cthing/escapers/HtmlEscaperTest.java
+++ b/src/test/java/org/cthing/escapers/HtmlEscaperTest.java
@@ -7,7 +7,6 @@
import java.io.IOException;
import java.io.StringWriter;
-import java.io.Writer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -22,7 +21,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIndexOutOfBoundsException;
import static org.cthing.escapers.HtmlEscaper.Option;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -189,9 +187,6 @@ public void testErrors() throws IOException {
HtmlEscaper.escape((char[])null, writer);
assertThat(writer.toString()).isEmpty();
- assertThatIllegalArgumentException().isThrownBy(() -> HtmlEscaper.escape("hello", (Writer)null));
- assertThatIllegalArgumentException().isThrownBy(() -> HtmlEscaper.escape("hello".toCharArray(), (Writer)null));
-
assertThatIndexOutOfBoundsException().isThrownBy(() -> HtmlEscaper.escape("hello".toCharArray(), -1, 3));
assertThatIndexOutOfBoundsException().isThrownBy(() -> HtmlEscaper.escape("hello".toCharArray(), 0, 20));
assertThatIndexOutOfBoundsException().isThrownBy(() -> HtmlEscaper.escape("hello".toCharArray(), 0, -1));
diff --git a/src/test/java/org/cthing/escapers/JavaEscaperTest.java b/src/test/java/org/cthing/escapers/JavaEscaperTest.java
index 5f47674..9bfe88b 100644
--- a/src/test/java/org/cthing/escapers/JavaEscaperTest.java
+++ b/src/test/java/org/cthing/escapers/JavaEscaperTest.java
@@ -7,7 +7,6 @@
import java.io.IOException;
import java.io.StringWriter;
-import java.io.Writer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -22,7 +21,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIndexOutOfBoundsException;
import static org.cthing.escapers.JavaEscaper.Option;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -194,9 +192,6 @@ public void testErrors() throws IOException {
JavaEscaper.escape((char[])null, writer);
assertThat(writer.toString()).isEmpty();
- assertThatIllegalArgumentException().isThrownBy(() -> JavaEscaper.escape("hello", (Writer)null));
- assertThatIllegalArgumentException().isThrownBy(() -> JavaEscaper.escape("hello".toCharArray(), (Writer)null));
-
assertThatIndexOutOfBoundsException().isThrownBy(() -> JavaEscaper.escape("hello".toCharArray(), -1, 3));
assertThatIndexOutOfBoundsException().isThrownBy(() -> JavaEscaper.escape("hello".toCharArray(), 0, 20));
assertThatIndexOutOfBoundsException().isThrownBy(() -> JavaEscaper.escape("hello".toCharArray(), 0, -1));
diff --git a/src/test/java/org/cthing/escapers/JavaScriptEscaperTest.java b/src/test/java/org/cthing/escapers/JavaScriptEscaperTest.java
index b0b5b67..4e7589d 100644
--- a/src/test/java/org/cthing/escapers/JavaScriptEscaperTest.java
+++ b/src/test/java/org/cthing/escapers/JavaScriptEscaperTest.java
@@ -7,7 +7,6 @@
import java.io.IOException;
import java.io.StringWriter;
-import java.io.Writer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -22,7 +21,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIndexOutOfBoundsException;
import static org.cthing.escapers.JavaScriptEscaper.Option;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -176,10 +174,6 @@ public void testErrors() throws IOException {
JavaScriptEscaper.escape((char[])null, writer);
assertThat(writer.toString()).isEmpty();
- assertThatIllegalArgumentException().isThrownBy(() -> JavaScriptEscaper.escape("hello", (Writer)null));
- assertThatIllegalArgumentException().isThrownBy(() -> JavaScriptEscaper.escape("hello".toCharArray(),
- (Writer)null));
-
assertThatIndexOutOfBoundsException().isThrownBy(() -> JavaScriptEscaper.escape("hello".toCharArray(), -1, 3));
assertThatIndexOutOfBoundsException().isThrownBy(() -> JavaScriptEscaper.escape("hello".toCharArray(), 0, 20));
assertThatIndexOutOfBoundsException().isThrownBy(() -> JavaScriptEscaper.escape("hello".toCharArray(), 0, -1));
diff --git a/src/test/java/org/cthing/escapers/JsonEscaperTest.java b/src/test/java/org/cthing/escapers/JsonEscaperTest.java
index 0d69d56..aa35df5 100644
--- a/src/test/java/org/cthing/escapers/JsonEscaperTest.java
+++ b/src/test/java/org/cthing/escapers/JsonEscaperTest.java
@@ -7,7 +7,6 @@
import java.io.IOException;
import java.io.StringWriter;
-import java.io.Writer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -22,7 +21,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIndexOutOfBoundsException;
import static org.cthing.escapers.JsonEscaper.Option;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -168,9 +166,6 @@ public void testErrors() throws IOException {
JsonEscaper.escape((char[])null, writer);
assertThat(writer.toString()).isEmpty();
- assertThatIllegalArgumentException().isThrownBy(() -> JsonEscaper.escape("hello", (Writer)null));
- assertThatIllegalArgumentException().isThrownBy(() -> JsonEscaper.escape("hello".toCharArray(), (Writer)null));
-
assertThatIndexOutOfBoundsException().isThrownBy(() -> JsonEscaper.escape("hello".toCharArray(), -1, 3));
assertThatIndexOutOfBoundsException().isThrownBy(() -> JsonEscaper.escape("hello".toCharArray(), 0, 20));
assertThatIndexOutOfBoundsException().isThrownBy(() -> JsonEscaper.escape("hello".toCharArray(), 0, -1));
diff --git a/src/test/java/org/cthing/escapers/XmlEscaperTest.java b/src/test/java/org/cthing/escapers/XmlEscaperTest.java
index 9db1822..2ef0d5e 100644
--- a/src/test/java/org/cthing/escapers/XmlEscaperTest.java
+++ b/src/test/java/org/cthing/escapers/XmlEscaperTest.java
@@ -7,7 +7,6 @@
import java.io.IOException;
import java.io.StringWriter;
-import java.io.Writer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -22,7 +21,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIndexOutOfBoundsException;
import static org.cthing.escapers.XmlEscaper.Option;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -192,9 +190,6 @@ public void testErrors() throws IOException {
XmlEscaper.escape((char[])null, writer);
assertThat(writer.toString()).isEmpty();
- assertThatIllegalArgumentException().isThrownBy(() -> XmlEscaper.escape("hello", (Writer)null));
- assertThatIllegalArgumentException().isThrownBy(() -> XmlEscaper.escape("hello".toCharArray(), (Writer)null));
-
assertThatIndexOutOfBoundsException().isThrownBy(() -> XmlEscaper.escape("hello".toCharArray(), -1, 3));
assertThatIndexOutOfBoundsException().isThrownBy(() -> XmlEscaper.escape("hello".toCharArray(), 0, 20));
assertThatIndexOutOfBoundsException().isThrownBy(() -> XmlEscaper.escape("hello".toCharArray(), 0, -1));
diff --git a/src/test/java/org/cthing/escapers/YamlEscaperTest.java b/src/test/java/org/cthing/escapers/YamlEscaperTest.java
index afc0265..b43a6e5 100644
--- a/src/test/java/org/cthing/escapers/YamlEscaperTest.java
+++ b/src/test/java/org/cthing/escapers/YamlEscaperTest.java
@@ -7,7 +7,6 @@
import java.io.IOException;
import java.io.StringWriter;
-import java.io.Writer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -23,7 +22,6 @@
import org.junit.jupiter.params.provider.MethodSource;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIndexOutOfBoundsException;
import static org.cthing.escapers.YamlEscaper.Option;
import static org.junit.jupiter.params.provider.Arguments.arguments;
@@ -265,9 +263,6 @@ public void testErrors() throws IOException {
YamlEscaper.escape((char[])null, writer);
assertThat(writer.toString()).isEmpty();
- assertThatIllegalArgumentException().isThrownBy(() -> YamlEscaper.escape("hello", (Writer)null));
- assertThatIllegalArgumentException().isThrownBy(() -> YamlEscaper.escape("hello".toCharArray(), (Writer)null));
-
assertThatIndexOutOfBoundsException().isThrownBy(() -> YamlEscaper.escape("hello".toCharArray(), -1, 3));
assertThatIndexOutOfBoundsException().isThrownBy(() -> YamlEscaper.escape("hello".toCharArray(), 0, 20));
assertThatIndexOutOfBoundsException().isThrownBy(() -> YamlEscaper.escape("hello".toCharArray(), 0, -1));