Skip to content

Make EncoderException a RuntimeException #1180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions encoders/firebase-encoders-json/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
package com.google.firebase.encoders {

public interface DataEncoder {
method public void encode(@NonNull Object, @NonNull java.io.Writer) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public String encode(@NonNull Object) throws com.google.firebase.encoders.EncodingException;
method public void encode(@NonNull Object, @NonNull java.io.Writer) throws java.io.IOException;
method @NonNull public String encode(@NonNull Object);
}

public final class EncodingException extends java.lang.Exception {
public final class EncodingException extends java.lang.RuntimeException {
ctor public EncodingException(@NonNull String);
ctor public EncodingException(@NonNull String, @NonNull Exception);
}
Expand All @@ -15,25 +15,25 @@ package com.google.firebase.encoders {
}

public interface ObjectEncoderContext {
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, @Nullable Object) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, double) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, int) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, long) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, boolean) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext inline(@Nullable Object) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, @Nullable Object) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, double) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, int) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, long) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext add(@NonNull String, boolean) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext inline(@Nullable Object) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ObjectEncoderContext nested(@NonNull String) throws java.io.IOException;
}

public interface ValueEncoder<T> {
}

public interface ValueEncoderContext {
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(@Nullable String) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(double) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(int) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(long) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(boolean) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(@NonNull byte[]) throws com.google.firebase.encoders.EncodingException, java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(@Nullable String) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(double) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(int) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(long) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(boolean) throws java.io.IOException;
method @NonNull public com.google.firebase.encoders.ValueEncoderContext add(@NonNull byte[]) throws java.io.IOException;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ private static final class TimestampEncoder implements ValueEncoder<Date> {
}

@Override
public void encode(@NonNull Date o, @NonNull ValueEncoderContext ctx)
throws EncodingException, IOException {
public void encode(@NonNull Date o, @NonNull ValueEncoderContext ctx) throws IOException {
ctx.add(rfc339.format(o));
}
}
Expand Down Expand Up @@ -108,8 +107,7 @@ public JsonDataEncoderBuilder configureWith(@NonNull Configurator config) {
public DataEncoder build() {
return new DataEncoder() {
@Override
public void encode(@NonNull Object o, @NonNull Writer writer)
throws IOException, EncodingException {
public void encode(@NonNull Object o, @NonNull Writer writer) throws IOException {
JsonValueObjectEncoderContext encoderContext =
new JsonValueObjectEncoderContext(
writer, objectEncoders, valueEncoders, fallbackEncoder);
Expand All @@ -118,7 +116,7 @@ public void encode(@NonNull Object o, @NonNull Writer writer)
}

@Override
public String encode(@NonNull Object o) throws EncodingException {
public String encode(@NonNull Object o) {
StringWriter stringWriter = new StringWriter();
try {
encode(o, stringWriter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private JsonValueObjectEncoderContext(JsonValueObjectEncoderContext anotherConte
@NonNull
@Override
public JsonValueObjectEncoderContext add(@NonNull String name, @Nullable Object o)
throws IOException, EncodingException {
throws IOException {
maybeUnNest();
jsonWriter.name(name);
if (o == null) {
Expand All @@ -71,43 +71,39 @@ public JsonValueObjectEncoderContext add(@NonNull String name, @Nullable Object

@NonNull
@Override
public JsonValueObjectEncoderContext add(@NonNull String name, double value)
throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(@NonNull String name, double value) throws IOException {
maybeUnNest();
jsonWriter.name(name);
return add(value);
}

@NonNull
@Override
public JsonValueObjectEncoderContext add(@NonNull String name, int value)
throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(@NonNull String name, int value) throws IOException {
maybeUnNest();
jsonWriter.name(name);
return add(value);
}

@NonNull
@Override
public JsonValueObjectEncoderContext add(@NonNull String name, long value)
throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(@NonNull String name, long value) throws IOException {
maybeUnNest();
jsonWriter.name(name);
return add(value);
}

@NonNull
@Override
public JsonValueObjectEncoderContext add(@NonNull String name, boolean value)
throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(@NonNull String name, boolean value) throws IOException {
maybeUnNest();
jsonWriter.name(name);
return add(value);
}

@NonNull
@Override
public ObjectEncoderContext inline(@Nullable Object value) throws IOException, EncodingException {
public ObjectEncoderContext inline(@Nullable Object value) throws IOException {
return add(value, true);
}

Expand All @@ -123,49 +119,47 @@ public ObjectEncoderContext nested(@NonNull String name) throws IOException {

@NonNull
@Override
public JsonValueObjectEncoderContext add(@Nullable String value)
throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(@Nullable String value) throws IOException {
maybeUnNest();
jsonWriter.value(value);
return this;
}

@NonNull
@Override
public JsonValueObjectEncoderContext add(double value) throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(double value) throws IOException {
maybeUnNest();
jsonWriter.value(value);
return this;
}

@NonNull
@Override
public JsonValueObjectEncoderContext add(int value) throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(int value) throws IOException {
maybeUnNest();
jsonWriter.value(value);
return this;
}

@NonNull
@Override
public JsonValueObjectEncoderContext add(long value) throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(long value) throws IOException {
maybeUnNest();
jsonWriter.value(value);
return this;
}

@NonNull
@Override
public JsonValueObjectEncoderContext add(boolean value) throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(boolean value) throws IOException {
maybeUnNest();
jsonWriter.value(value);
return this;
}

@NonNull
@Override
public JsonValueObjectEncoderContext add(@Nullable byte[] bytes)
throws IOException, EncodingException {
public JsonValueObjectEncoderContext add(@Nullable byte[] bytes) throws IOException {
maybeUnNest();
if (bytes == null) {
jsonWriter.nullValue();
Expand All @@ -176,8 +170,7 @@ public JsonValueObjectEncoderContext add(@Nullable byte[] bytes)
}

@NonNull
JsonValueObjectEncoderContext add(@Nullable Object o, boolean inline)
throws IOException, EncodingException {
JsonValueObjectEncoderContext add(@Nullable Object o, boolean inline) throws IOException {
if (inline && cannotBeInline(o)) {
throw new EncodingException(
String.format("%s cannot be encoded inline", o == null ? null : o.getClass()));
Expand Down Expand Up @@ -278,7 +271,7 @@ JsonValueObjectEncoderContext add(@Nullable Object o, boolean inline)
}

JsonValueObjectEncoderContext doEncode(ObjectEncoder<Object> encoder, Object o, boolean inline)
throws IOException, EncodingException {
throws IOException {
if (!inline) jsonWriter.beginObject();
encoder.encode(o, this);
if (!inline) jsonWriter.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
public interface DataEncoder {

/** Encodes {@code obj} into {@code writer}. */
void encode(@NonNull Object obj, @NonNull Writer writer) throws IOException, EncodingException;
void encode(@NonNull Object obj, @NonNull Writer writer) throws IOException;

/** Returns the string-encoded representation of {@code obj}. */
@NonNull
String encode(@NonNull Object obj) throws EncodingException;
String encode(@NonNull Object obj);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
interface Encoder<TValue, TContext> {

/** Encode {@code obj} using {@code TContext}. */
void encode(@NonNull TValue obj, @NonNull TContext context) throws EncodingException, IOException;
void encode(@NonNull TValue obj, @NonNull TContext context) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* An exception thrown when an {@code Encoder} ends up in an invalid state, or if the provided
* object is in an state that cannot be encoded.
*/
public final class EncodingException extends Exception {
public final class EncodingException extends RuntimeException {

/** Creates a {@code EncodingException} with the given message. */
public EncodingException(@NonNull String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,23 @@ public interface ObjectEncoderContext {
* by the encoders will be propagated.
*/
@NonNull
ObjectEncoderContext add(@NonNull String name, @Nullable Object obj)
throws IOException, EncodingException;
ObjectEncoderContext add(@NonNull String name, @Nullable Object obj) throws IOException;

/** Add an entry with {@code name} mapped to the encoded primitive type of {@code value}. */
@NonNull
ObjectEncoderContext add(@NonNull String name, double value)
throws IOException, EncodingException;
ObjectEncoderContext add(@NonNull String name, double value) throws IOException;

/** Add an entry with {@code name} mapped to the encoded primitive type of {@code value}. */
@NonNull
ObjectEncoderContext add(@NonNull String name, int value) throws IOException, EncodingException;
ObjectEncoderContext add(@NonNull String name, int value) throws IOException;

/** Add an entry with {@code name} mapped to the encoded primitive type of {@code value}. */
@NonNull
ObjectEncoderContext add(@NonNull String name, long value) throws IOException, EncodingException;
ObjectEncoderContext add(@NonNull String name, long value) throws IOException;

/** Add an entry with {@code name} mapped to the encoded primitive type of {@code value}. */
@NonNull
ObjectEncoderContext add(@NonNull String name, boolean value)
throws IOException, EncodingException;
ObjectEncoderContext add(@NonNull String name, boolean value) throws IOException;

/**
* Encodes a given object inline in current context.
Expand All @@ -87,7 +84,7 @@ ObjectEncoderContext add(@NonNull String name, boolean value)
* }</pre>
*/
@NonNull
ObjectEncoderContext inline(@Nullable Object value) throws IOException, EncodingException;
ObjectEncoderContext inline(@Nullable Object value) throws IOException;

/**
* Begin a nested JSON object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ public interface ValueEncoderContext {

/** Adds {@code value} as a primitive encoded value. */
@NonNull
ValueEncoderContext add(@Nullable String value) throws IOException, EncodingException;
ValueEncoderContext add(@Nullable String value) throws IOException;

/** Adds {@code value} as a primitive encoded value. */
@NonNull
ValueEncoderContext add(double value) throws IOException, EncodingException;
ValueEncoderContext add(double value) throws IOException;

/** Adds {@code value} as a primitive encoded value. */
@NonNull
ValueEncoderContext add(int value) throws IOException, EncodingException;
ValueEncoderContext add(int value) throws IOException;

/** Adds {@code value} as a primitive encoded value. */
@NonNull
ValueEncoderContext add(long value) throws IOException, EncodingException;
ValueEncoderContext add(long value) throws IOException;

/** Adds {@code value} as a primitive encoded value. */
@NonNull
ValueEncoderContext add(boolean value) throws IOException, EncodingException;
ValueEncoderContext add(boolean value) throws IOException;

/** Adds {@code value} as a encoded array of bytes. */
@NonNull
ValueEncoderContext add(@NonNull byte[] bytes) throws IOException, EncodingException;
ValueEncoderContext add(@NonNull byte[] bytes) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.firebase.encoders.DataEncoder;
import com.google.firebase.encoders.EncodingException;
import com.google.firebase.encoders.ObjectEncoderContext;
import com.google.firebase.encoders.ValueEncoderContext;
import java.util.Collections;
Expand All @@ -30,7 +29,7 @@ public class JsonDataEncoderBuilderTests {
static class Foo {}

@Test
public void configureWith_shouldCorrectlyRegisterObjectEncoder() throws EncodingException {
public void configureWith_shouldCorrectlyRegisterObjectEncoder() {
DataEncoder encoder =
new JsonDataEncoderBuilder()
.configureWith(
Expand All @@ -46,7 +45,7 @@ public void configureWith_shouldCorrectlyRegisterObjectEncoder() throws Encoding
}

@Test
public void configureWith_shouldCorrectlyRegisterValueEncoder() throws EncodingException {
public void configureWith_shouldCorrectlyRegisterValueEncoder() {
DataEncoder encoder =
new JsonDataEncoderBuilder()
.configureWith(
Expand Down
Loading