diff --git a/moshi/src/main/java/com/squareup/moshi/JsonReader.java b/moshi/src/main/java/com/squareup/moshi/JsonReader.java index 29863bb..eabc01a 100644 --- a/moshi/src/main/java/com/squareup/moshi/JsonReader.java +++ b/moshi/src/main/java/com/squareup/moshi/JsonReader.java @@ -312,25 +312,25 @@ public abstract class JsonReader implements Closeable { /** * Returns true if the current array or object has another element. */ - public abstract boolean hasNext() throws IOException; + @CheckReturnValue public abstract boolean hasNext() throws IOException; /** * Returns the type of the next token without consuming it. */ - public abstract Token peek() throws IOException; + @CheckReturnValue public abstract Token peek() throws IOException; /** * Returns the next token, a {@linkplain Token#NAME property name}, and consumes it. * * @throws JsonDataException if the next token in the stream is not a property name. */ - public abstract String nextName() throws IOException; + @CheckReturnValue public abstract String nextName() throws IOException; /** * If the next token is a {@linkplain Token#NAME property name} that's in {@code options}, this * consumes it and returns its index. Otherwise this returns -1 and no name is consumed. */ - public abstract int selectName(Options options) throws IOException; + @CheckReturnValue public abstract int selectName(Options options) throws IOException; /** * Skips the next token, consuming it. This method is intended for use when the JSON token stream @@ -353,7 +353,7 @@ public abstract class JsonReader implements Closeable { * If the next token is a {@linkplain Token#STRING string} that's in {@code options}, this * consumes it and returns its index. Otherwise this returns -1 and no string is consumed. */ - public abstract int selectString(Options options) throws IOException; + @CheckReturnValue public abstract int selectString(Options options) throws IOException; /** * Returns the {@linkplain Token#BOOLEAN boolean} value of the next token, consuming it. diff --git a/moshi/src/test/java/com/squareup/moshi/JsonReaderPathTest.java b/moshi/src/test/java/com/squareup/moshi/JsonReaderPathTest.java index 875232e..9950ccf 100644 --- a/moshi/src/test/java/com/squareup/moshi/JsonReaderPathTest.java +++ b/moshi/src/test/java/com/squareup/moshi/JsonReaderPathTest.java @@ -35,6 +35,7 @@ public final class JsonReaderPathTest { return JsonCodecFactory.factories(); } + @SuppressWarnings("CheckReturnValue") @Test public void path() throws IOException { JsonReader reader = factory.newReader("{\"a\":[2,true,false,null,\"b\",{\"c\":\"d\"},[3]]}"); assertThat(reader.getPath()).isEqualTo("$"); @@ -114,6 +115,7 @@ public final class JsonReaderPathTest { assertThat(reader.getPath()).isEqualTo("$"); } + @SuppressWarnings("CheckReturnValue") @Test public void objectPath() throws IOException { JsonReader reader = factory.newReader("{\"a\":1,\"b\":2}"); assertThat(reader.getPath()).isEqualTo("$"); @@ -154,6 +156,7 @@ public final class JsonReaderPathTest { assertThat(reader.getPath()).isEqualTo("$"); } + @SuppressWarnings("CheckReturnValue") @Test public void arrayPath() throws IOException { JsonReader reader = factory.newReader("[1,2]"); assertThat(reader.getPath()).isEqualTo("$"); @@ -212,6 +215,7 @@ public final class JsonReaderPathTest { assertThat(reader.getPath()).isEqualTo("$.null"); } + @SuppressWarnings("CheckReturnValue") @Test public void skipObjectValues() throws IOException { JsonReader reader = factory.newReader("{\"a\":1,\"b\":2}"); reader.beginObject(); diff --git a/moshi/src/test/java/com/squareup/moshi/JsonUtf8ReaderTest.java b/moshi/src/test/java/com/squareup/moshi/JsonUtf8ReaderTest.java index 7f1a504..7652b1c 100644 --- a/moshi/src/test/java/com/squareup/moshi/JsonUtf8ReaderTest.java +++ b/moshi/src/test/java/com/squareup/moshi/JsonUtf8ReaderTest.java @@ -393,6 +393,7 @@ public final class JsonUtf8ReaderTest { } } + @SuppressWarnings("CheckReturnValue") @Test public void prematurelyClosed() throws IOException { try { JsonReader reader = newReader("{\"a\":[]}"); @@ -977,6 +978,7 @@ public final class JsonUtf8ReaderTest { } } + @SuppressWarnings("CheckReturnValue") @Test public void failWithPositionDeepPath() throws IOException { JsonReader reader = newReader("[1,{\"a\":[2,3,}"); reader.beginArray();