From 6a27a65c9d934d7c3f7a7b2252680c28e54b2bd9 Mon Sep 17 00:00:00 2001 From: Marten Voorberg Date: Tue, 7 Mar 2023 13:39:26 +0100 Subject: [PATCH] Fix #45: Resolve various comments by Marcono1234 --- .../java/com/google/gson/GsonBuilder.java | 4 +-- .../main/java/com/google/gson/Strictness.java | 21 +++++++++------- .../com/google/gson/stream/JsonReader.java | 25 +++++++++---------- .../com/google/gson/stream/JsonWriter.java | 9 ++++--- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/gson/src/main/java/com/google/gson/GsonBuilder.java b/gson/src/main/java/com/google/gson/GsonBuilder.java index 2b8f2af1c6..c7e81a2698 100644 --- a/gson/src/main/java/com/google/gson/GsonBuilder.java +++ b/gson/src/main/java/com/google/gson/GsonBuilder.java @@ -530,13 +530,13 @@ public GsonBuilder setLenient() { * * @param strictness the new strictness method of this factory. May not be null. * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern. - * @throws NullPointerException if the provided strictness is null. + * @throws NullPointerException if the provided {@code strictness} is {@code null}. * @see JsonWriter#setStrictness(Strictness) * @see JsonReader#setStrictness(Strictness) * @since $next-version$ */ public GsonBuilder setStrictness(Strictness strictness) { - this.strictness = Objects.requireNonNull(strictness);; + this.strictness = Objects.requireNonNull(strictness); return this; } diff --git a/gson/src/main/java/com/google/gson/Strictness.java b/gson/src/main/java/com/google/gson/Strictness.java index f34c89ed07..14895faadf 100644 --- a/gson/src/main/java/com/google/gson/Strictness.java +++ b/gson/src/main/java/com/google/gson/Strictness.java @@ -1,17 +1,20 @@ package com.google.gson; +import com.google.gson.stream.JsonWriter; +import com.google.gson.stream.JsonReader; + /** - * Modes that indicate how strictly a JSON {@linkplain com.google.gson.stream.JsonReader reader} or - * {@linkplain com.google.gson.stream.JsonWriter writer} follows the syntax laid out in the - * RFC 8259 JSON specification. + * Modes that indicate how strictly a JSON {@linkplain JsonReader reader} or + * {@linkplain JsonWriter writer} follows the syntax laid out in the + * RFC 8259 JSON specification. * - *

You can look at {@link com.google.gson.stream.JsonWriter#setStrictness(Strictness)} to see how the strictness - * affects the {@link com.google.gson.stream.JsonWriter} and you can look at - * {@link com.google.gson.stream.JsonReader#setStrictness(Strictness)} to see how the strictness - * affects the {@link com.google.gson.stream.JsonReader}

+ *

You can look at {@link JsonWriter#setStrictness(Strictness)} to see how the strictness + * affects the {@link JsonWriter} and you can look at + * {@link JsonReader#setStrictness(Strictness)} to see how the strictness + * affects the {@link JsonReader}.

* - * @see com.google.gson.stream.JsonReader#setStrictness(Strictness) - * @see com.google.gson.stream.JsonWriter#setStrictness(Strictness) + * @see JsonReader#setStrictness(Strictness) + * @see JsonWriter#setStrictness(Strictness) * @since $next-version$ */ public enum Strictness { diff --git a/gson/src/main/java/com/google/gson/stream/JsonReader.java b/gson/src/main/java/com/google/gson/stream/JsonReader.java index e560c8325b..c3df38cf68 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonReader.java +++ b/gson/src/main/java/com/google/gson/stream/JsonReader.java @@ -293,7 +293,7 @@ public JsonReader(Reader in) { } /** - * Set the strictness this JSONReader to {@link Strictness#LENIENT} if the provided argument is true and + * Set the strictness this reader to {@link Strictness#LENIENT} if the provided argument is true and * set the strictness to {@link Strictness#DEFAULT} if the provided argument if false. * * @param lenient passing true will set the strictness of this reader to {@link Strictness#LENIENT} and @@ -305,7 +305,7 @@ public final void setLenient(boolean lenient) { } /** - * Returns true if the {@link Strictness} of this reader is equal to {@link Strictness#STRICT}. + * Returns true if the {@link Strictness} of this reader is equal to {@link Strictness#LENIENT}. * * @see #setStrictness(Strictness) */ @@ -317,21 +317,21 @@ public final boolean isLenient() { * Configure how liberal this parser is in what it accepts. * *

In {@linkplain Strictness#STRICT strict} mode, the - * parser only accepts JSON in accordance with RFC 8259. + * parser only accepts JSON in accordance with RFC 8259. * In {@linkplain Strictness#DEFAULT default} mode, only JSON in accordance with the RFC 8259 is accepted, with a few exceptions denoted below + * href="https://www.ietf.org/rfc/rfc8259.txt">RFC 8259 is accepted, with a few exceptions denoted below * for backwards compatibility reasons. In {@linkplain Strictness#LENIENT lenient} mode, * all sort of non-spec compliant JSON is accepted (see below).

* *
*
{@link Strictness#STRICT}
*
- * In strict mode, only input compliant with RFC 8259 + * In strict mode, only input compliant with RFC 8259 * is parsed. *
*
{@link Strictness#DEFAULT}
*
- * In default mode, the following departures from RFC 8259 + * In default mode, the following departures from RFC 8259 * are accepted: *
    *
  • JsonReader allows the literals {@code true}, {@code false} and {@code null} @@ -340,16 +340,15 @@ public final boolean isLenient() { *
  • JsonReader supports the escape sequence \LF (with {@code LF} * being the Unicode character U+000A), resulting in a {@code LF} within the * read JSON string - *
  • JsonReader allows unescaped control characters (U+0000 through U+001F) + *
  • JsonReader allows unescaped control characters (U+0000 through U+001F) *
*
*
{@link Strictness#LENIENT}
*
* In lenient mode, all input that is accepted in default mode is accepted in addition to the following - * departures from RFC 8259: + * departures from RFC 8259: *
    - *
  • Streams that start with the non-execute prefix, ")]}'\n" - * . + *
  • Streams that start with the non-execute prefix, {@code ")]}'\n"} *
  • Streams that include multiple top-level values. With default or strict parsing, * each stream must contain exactly one top-level value. *
  • Numbers may be {@link Double#isNaN() NaNs} or {@link Double#isInfinite() infinities} represented by @@ -370,7 +369,7 @@ public final boolean isLenient() { *
* * @param strictness the new strictness value of this reader. May not be null. - * @throws NullPointerException if the provided strictness is null. + * @throws NullPointerException if the provided {@code strictness} is {@code null}. * @since $next-version$ */ public final void setStrictness(Strictness strictness) { @@ -379,7 +378,7 @@ public final void setStrictness(Strictness strictness) { } /** - * Returns the {@linkplain Strictness strictness} of this writer. + * Returns the {@linkplain Strictness strictness} of this reader. * * @see #setStrictness(Strictness) * @since $next-version$ @@ -678,7 +677,7 @@ private int peekKeyword() throws IOException { // any upper case letters in the buffer are not matched keywordUpper = strictness == Strictness.STRICT ? keyword : keyword.toUpperCase(); - // Confirm that chars [1..length) match the keyword. + // Confirm that chars [0..length) match the keyword. int length = keyword.length(); for (int i = 0; i < length; i++) { if (pos + i >= limit && !fillBuffer(i + 1)) { diff --git a/gson/src/main/java/com/google/gson/stream/JsonWriter.java b/gson/src/main/java/com/google/gson/stream/JsonWriter.java index a6ff785f7f..4e115373a3 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonWriter.java +++ b/gson/src/main/java/com/google/gson/stream/JsonWriter.java @@ -269,7 +269,7 @@ public final void setLenient(boolean lenient) { } /** - * Returns true if this writer has a strictness value of {@link Strictness#LENIENT}, false otherwise. + * Returns true if this writer has a {@code strictness} value of {@link Strictness#LENIENT}, false otherwise. * * @see JsonWriter#setStrictness(Strictness) */ @@ -284,13 +284,14 @@ public boolean isLenient() { * * * @param strictness the new strictness of this writer. May not be null. - * @throws NullPointerException A null pointer exception is thrown if the provided strictness is null. + * @throws NullPointerException A null pointer exception is thrown if the provided {@code strictness} is {@code null}. * @since $next-version$ */ public final void setStrictness(Strictness strictness) {