Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions core/src/main/java/com/dropbox/core/AccessErrorException.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@

import com.dropbox.core.v2.auth.AccessError;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Gets thrown when invalid access occurs.
*/
public class AccessErrorException extends DbxException {
private static final long serialVersionUID = 0;

private final AccessError accessError;
private final @Nonnull AccessError accessError;

public AccessError getAccessError() {
public @Nonnull AccessError getAccessError() {
return accessError;
}

public AccessErrorException(String requestId, String message, AccessError accessError) {
public AccessErrorException(@Nullable String requestId,
@Nullable String message,
@Nonnull AccessError accessError) {
super(requestId, message);
this.accessError = accessError;
}
Expand Down
22 changes: 12 additions & 10 deletions core/src/main/java/com/dropbox/core/ApiErrorResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,46 @@

import com.dropbox.core.stone.StoneSerializer;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

final class ApiErrorResponse<T> {
private final T error;
private LocalizedText userMessage;
private final @Nonnull T error;
private @Nullable LocalizedText userMessage;

public ApiErrorResponse(T error, LocalizedText userMessage) {
public ApiErrorResponse(@Nonnull T error, @Nullable LocalizedText userMessage) {
if (error == null) {
throw new NullPointerException("error");
}
this.error = error;
this.userMessage = userMessage;
}

public T getError() {
public @Nonnull T getError() {
return error;
}

public LocalizedText getUserMessage() {
public @Nullable LocalizedText getUserMessage() {
return userMessage;
}

/**
* For internal use only.
*/
static final class Serializer<T> extends StoneSerializer<ApiErrorResponse<T>> {
private StoneSerializer<T> errSerializer;
private @Nonnull StoneSerializer<T> errSerializer;

public Serializer(StoneSerializer<T> errSerializer) {
public Serializer(@Nonnull StoneSerializer<T> errSerializer) {
this.errSerializer = errSerializer;
}

@Override
public void serialize(ApiErrorResponse<T> value, JsonGenerator g) throws IOException, JsonGenerationException {
public void serialize(@Nonnull ApiErrorResponse<T> value, @Nonnull JsonGenerator g) throws IOException, JsonGenerationException {
throw new UnsupportedOperationException("Error wrapper serialization not supported.");
}

@Override
public ApiErrorResponse<T> deserialize(JsonParser p) throws IOException, JsonParseException {
public @Nonnull ApiErrorResponse<T> deserialize(@Nonnull JsonParser p) throws IOException, JsonParseException {
T error = null;
LocalizedText userMessage = null;

Expand All @@ -73,4 +76,3 @@ public ApiErrorResponse<T> deserialize(JsonParser p) throws IOException, JsonPar
}
}
}

5 changes: 4 additions & 1 deletion core/src/main/java/com/dropbox/core/BadRequestException.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.dropbox.core;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* This is what is thrown when the Dropbox server tells us that it didn't like something about our
* request. This corresponds to the HTTP 400 status code.
*/
public class BadRequestException extends ProtocolException {
private static final long serialVersionUID = 0;

public BadRequestException(String requestId, String message) {
public BadRequestException(@Nullable String requestId, @Nullable String message) {
super(requestId, message);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.dropbox.core;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Thrown when the Dropbox server responds with an HTTP status code we didn't expect.
*/
Expand All @@ -8,12 +11,15 @@ public class BadResponseCodeException extends BadResponseException {

private final int statusCode;

public BadResponseCodeException(String requestId, String message, int statusCode) {
public BadResponseCodeException(@Nullable String requestId, @Nullable String message, int statusCode) {
super(requestId, message);
this.statusCode = statusCode;
}

public BadResponseCodeException(String requestId, String message, int statusCode, Throwable cause) {
public BadResponseCodeException(@Nullable String requestId,
@Nullable String message,
int statusCode,
@Nonnull Throwable cause) {
super(requestId, message, cause);
this.statusCode = statusCode;
}
Expand All @@ -27,4 +33,3 @@ public int getStatusCode() {
return statusCode;
}
}

8 changes: 5 additions & 3 deletions core/src/main/java/com/dropbox/core/BadResponseException.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.dropbox.core;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* Thrown when we the response from the Dropbox server isn't something we expect.
* For example, if the JSON returned by the server is malformed or missing fields.
*/
public class BadResponseException extends ProtocolException {
private static final long serialVersionUID = 0;

public BadResponseException(String requestId, String message) {
public BadResponseException(@Nullable String requestId, @Nullable String message) {
super(requestId, message);
}

public BadResponseException(String requestId, String message, Throwable cause) {
public BadResponseException(@Nullable String requestId, @Nullable String message, @Nonnull Throwable cause) {
super(requestId, message, cause);
}
}

21 changes: 14 additions & 7 deletions core/src/main/java/com/dropbox/core/DbxApiException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dropbox.core;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
Expand All @@ -8,14 +9,19 @@
public class DbxApiException extends DbxException {
private static final long serialVersionUID = 0L;

private final LocalizedText userMessage;
private final @Nullable LocalizedText userMessage;

public DbxApiException(String requestId, LocalizedText userMessage, String message) {
public DbxApiException(@Nullable String requestId,
@Nullable LocalizedText userMessage,
@Nonnull String message) {
super(requestId, message);
this.userMessage = userMessage;
}

public DbxApiException(String requestId, LocalizedText userMessage, String message, Throwable cause) {
public DbxApiException(@Nullable String requestId,
@Nullable LocalizedText userMessage,
@Nonnull String message,
@Nonnull Throwable cause) {
super(requestId, message, cause);
this.userMessage = userMessage;
}
Expand All @@ -27,16 +33,17 @@ public DbxApiException(String requestId, LocalizedText userMessage, String messa
*
* @return human-readable message to display to end user, or {@code null} if unavailable
*/
@Nullable
public LocalizedText getUserMessage() {
public @Nullable LocalizedText getUserMessage() {
return userMessage;
}

protected static String buildMessage(String routeName, LocalizedText userMessage) {
protected static @Nonnull String buildMessage(@Nonnull String routeName, @Nullable LocalizedText userMessage) {
return buildMessage(routeName, userMessage, null);
}

protected static String buildMessage(String routeName, LocalizedText userMessage, Object errorValue) {
protected static @Nonnull String buildMessage(@Nonnull String routeName,
@Nullable LocalizedText userMessage,
@Nullable Object errorValue) {
StringBuilder sb = new StringBuilder();
sb.append("Exception in ").append(routeName);
if (errorValue != null) {
Expand Down
45 changes: 23 additions & 22 deletions core/src/main/java/com/dropbox/core/DbxAppInfo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dropbox.core;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;

import static com.dropbox.core.util.StringUtil.jq;
Expand All @@ -13,15 +15,14 @@
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

/*>>> import checkers.nullness.quals.Nullable; */

/**
* Identifying information about your application.
*/
public class DbxAppInfo extends Dumpable {
private final String key;
private final String secret;
private final DbxHost host;
private final @Nonnull String key;
private final @Nullable String secret;
private final @Nonnull DbxHost host;

/**
*
Expand All @@ -30,15 +31,15 @@ public class DbxAppInfo extends Dumpable {
* @param key Dropbox app key (see {@link #getKey})
* @see com.dropbox.core.DbxPKCEWebAuth
*/
public DbxAppInfo(String key) {
public DbxAppInfo(@Nonnull String key) {
this(key, null);
}

/**
* @param key Dropbox app key (see {@link #getKey})
* @param secret Dropbox app secret (see {@link #getSecret})
*/
public DbxAppInfo(String key, String secret) {
public DbxAppInfo(@Nonnull String key, @Nullable String secret) {
checkKeyArg(key);
checkSecretArg(secret);

Expand All @@ -52,7 +53,7 @@ public DbxAppInfo(String key, String secret) {
* @param secret Dropbox app secret (see {@link #getSecret})
* @param host Dropbox host configuration (see {@link #getHost})
*/
public DbxAppInfo(String key, String secret, DbxHost host) {
public DbxAppInfo(@Nonnull String key, @Nullable String secret, @Nonnull DbxHost host) {
checkKeyArg(key);
checkSecretArg(secret);

Expand All @@ -68,7 +69,7 @@ public DbxAppInfo(String key, String secret, DbxHost host) {
*
* @return Dropbox app key
*/
public String getKey() {
public @Nonnull String getKey() {
return key;
}

Expand All @@ -83,7 +84,7 @@ public String getKey() {
*
* @return Dropbox app secret
*/
public String getSecret() {
public @Nullable String getSecret() {
return secret;
}

Expand All @@ -95,7 +96,7 @@ public String getSecret() {
*
* @return Dropbox host configuration
*/
public DbxHost getHost() {
public @Nonnull DbxHost getHost() {
return host;
}

Expand All @@ -110,7 +111,7 @@ public boolean hasSecret() {
}

@Override
protected void dumpFields(DumpWriter out) {
protected void dumpFields(@Nonnull DumpWriter out) {
out.f("key").v(key);
out.f("secret").v(secret);
}
Expand All @@ -125,7 +126,7 @@ protected void dumpFields(DumpWriter out) {
* that what you passed in is an actual valid Dropbox API app key.
* </p>
*/
public static /*@Nullable*/String getKeyFormatError(String key) {
public static @Nullable String getKeyFormatError(@Nullable String key) {
return getTokenPartError(key);
}

Expand All @@ -139,17 +140,17 @@ protected void dumpFields(DumpWriter out) {
* you passed in is an actual valid Dropbox API app key.
* </p>
*/
public static /*@Nullable*/String getSecretFormatError(String key) {
public static @Nullable String getSecretFormatError(@Nullable String key) {
return getTokenPartError(key);
}

// ------------------------------------------------------
// JSON parsing

public static final JsonReader<DbxAppInfo> Reader = new JsonReader<DbxAppInfo>()
public static final @Nonnull JsonReader<DbxAppInfo> Reader = new JsonReader<DbxAppInfo>()
{
@Override
public final DbxAppInfo read(JsonParser parser)
public final @Nonnull DbxAppInfo read(@Nonnull JsonParser parser)
throws IOException, JsonReadException
{
JsonLocation top = JsonReader.expectObjectStart(parser);
Expand Down Expand Up @@ -191,10 +192,10 @@ else if (fieldName.equals("host")) {
}
};

public static final JsonReader<String> KeyReader = new JsonReader<String>()
public static final @Nonnull JsonReader<String> KeyReader = new JsonReader<String>()
{
@Override
public String read(JsonParser parser) throws IOException, JsonReadException
public @Nonnull String read(@Nonnull JsonParser parser) throws IOException, JsonReadException
{
try {
String v = parser.getText();
Expand All @@ -211,10 +212,10 @@ public String read(JsonParser parser) throws IOException, JsonReadException
}
};

public static final JsonReader<String> SecretReader = new JsonReader<String>()
public static final @Nonnull JsonReader<String> SecretReader = new JsonReader<String>()
{
@Override
public String read(JsonParser parser) throws IOException, JsonReadException
public @Nonnull String read(@Nonnull JsonParser parser) throws IOException, JsonReadException
{
try {
String v = parser.getText();
Expand All @@ -232,7 +233,7 @@ public String read(JsonParser parser) throws IOException, JsonReadException

};

public static /*@Nullable*/String getTokenPartError(String s)
public static @Nullable String getTokenPartError(@Nullable String s)
{
if (s == null) return null;
if (s.length() == 0) return "can't be empty";
Expand All @@ -246,7 +247,7 @@ public String read(JsonParser parser) throws IOException, JsonReadException
return null;
}

public static void checkKeyArg(String key)
public static void checkKeyArg(@Nullable String key)
{
String error;

Expand All @@ -260,7 +261,7 @@ public static void checkKeyArg(String key)
throw new IllegalArgumentException("Bad 'key': " + error);
}

public static void checkSecretArg(String secret)
public static void checkSecretArg(@Nullable String secret)
{
String error = getTokenPartError(secret);
if (error == null) return;
Expand Down
Loading
Loading