diff --git a/core/src/main/java/com/dropbox/core/AccessErrorException.java b/core/src/main/java/com/dropbox/core/AccessErrorException.java
index f46f757ac..e9a5f3bff 100644
--- a/core/src/main/java/com/dropbox/core/AccessErrorException.java
+++ b/core/src/main/java/com/dropbox/core/AccessErrorException.java
@@ -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;
}
diff --git a/core/src/main/java/com/dropbox/core/ApiErrorResponse.java b/core/src/main/java/com/dropbox/core/ApiErrorResponse.java
index 701a8106d..6060a97a2 100644
--- a/core/src/main/java/com/dropbox/core/ApiErrorResponse.java
+++ b/core/src/main/java/com/dropbox/core/ApiErrorResponse.java
@@ -10,11 +10,14 @@
import com.dropbox.core.stone.StoneSerializer;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
final class ApiErrorResponse {
- 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");
}
@@ -22,11 +25,11 @@ public ApiErrorResponse(T error, LocalizedText userMessage) {
this.userMessage = userMessage;
}
- public T getError() {
+ public @Nonnull T getError() {
return error;
}
- public LocalizedText getUserMessage() {
+ public @Nullable LocalizedText getUserMessage() {
return userMessage;
}
@@ -34,19 +37,19 @@ public LocalizedText getUserMessage() {
* For internal use only.
*/
static final class Serializer extends StoneSerializer> {
- private StoneSerializer errSerializer;
+ private @Nonnull StoneSerializer errSerializer;
- public Serializer(StoneSerializer errSerializer) {
+ public Serializer(@Nonnull StoneSerializer errSerializer) {
this.errSerializer = errSerializer;
}
@Override
- public void serialize(ApiErrorResponse value, JsonGenerator g) throws IOException, JsonGenerationException {
+ public void serialize(@Nonnull ApiErrorResponse value, @Nonnull JsonGenerator g) throws IOException, JsonGenerationException {
throw new UnsupportedOperationException("Error wrapper serialization not supported.");
}
@Override
- public ApiErrorResponse deserialize(JsonParser p) throws IOException, JsonParseException {
+ public @Nonnull ApiErrorResponse deserialize(@Nonnull JsonParser p) throws IOException, JsonParseException {
T error = null;
LocalizedText userMessage = null;
@@ -73,4 +76,3 @@ public ApiErrorResponse deserialize(JsonParser p) throws IOException, JsonPar
}
}
}
-
diff --git a/core/src/main/java/com/dropbox/core/BadRequestException.java b/core/src/main/java/com/dropbox/core/BadRequestException.java
index 2aa27f641..4c0d1640d 100644
--- a/core/src/main/java/com/dropbox/core/BadRequestException.java
+++ b/core/src/main/java/com/dropbox/core/BadRequestException.java
@@ -1,5 +1,8 @@
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.
@@ -7,7 +10,7 @@
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);
}
}
diff --git a/core/src/main/java/com/dropbox/core/BadResponseCodeException.java b/core/src/main/java/com/dropbox/core/BadResponseCodeException.java
index 652bb941b..5b58aa9e7 100644
--- a/core/src/main/java/com/dropbox/core/BadResponseCodeException.java
+++ b/core/src/main/java/com/dropbox/core/BadResponseCodeException.java
@@ -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.
*/
@@ -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;
}
@@ -27,4 +33,3 @@ public int getStatusCode() {
return statusCode;
}
}
-
diff --git a/core/src/main/java/com/dropbox/core/BadResponseException.java b/core/src/main/java/com/dropbox/core/BadResponseException.java
index c29ad5ff8..7daa29e5b 100644
--- a/core/src/main/java/com/dropbox/core/BadResponseException.java
+++ b/core/src/main/java/com/dropbox/core/BadResponseException.java
@@ -1,5 +1,8 @@
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.
@@ -7,12 +10,11 @@
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);
}
}
-
diff --git a/core/src/main/java/com/dropbox/core/DbxApiException.java b/core/src/main/java/com/dropbox/core/DbxApiException.java
index 2b96328e2..01a624b46 100644
--- a/core/src/main/java/com/dropbox/core/DbxApiException.java
+++ b/core/src/main/java/com/dropbox/core/DbxApiException.java
@@ -1,5 +1,6 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
@@ -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;
}
@@ -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) {
diff --git a/core/src/main/java/com/dropbox/core/DbxAppInfo.java b/core/src/main/java/com/dropbox/core/DbxAppInfo.java
index 4183e2e80..6b715b60b 100644
--- a/core/src/main/java/com/dropbox/core/DbxAppInfo.java
+++ b/core/src/main/java/com/dropbox/core/DbxAppInfo.java
@@ -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;
@@ -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;
/**
*
@@ -30,7 +31,7 @@ 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);
}
@@ -38,7 +39,7 @@ public DbxAppInfo(String key) {
* @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);
@@ -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);
@@ -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;
}
@@ -83,7 +84,7 @@ public String getKey() {
*
* @return Dropbox app secret
*/
- public String getSecret() {
+ public @Nullable String getSecret() {
return secret;
}
@@ -95,7 +96,7 @@ public String getSecret() {
*
* @return Dropbox host configuration
*/
- public DbxHost getHost() {
+ public @Nonnull DbxHost getHost() {
return host;
}
@@ -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);
}
@@ -125,7 +126,7 @@ protected void dumpFields(DumpWriter out) {
* that what you passed in is an actual valid Dropbox API app key.
*
*/
- public static /*@Nullable*/String getKeyFormatError(String key) {
+ public static @Nullable String getKeyFormatError(@Nullable String key) {
return getTokenPartError(key);
}
@@ -139,17 +140,17 @@ protected void dumpFields(DumpWriter out) {
* you passed in is an actual valid Dropbox API app key.
*
*/
- public static /*@Nullable*/String getSecretFormatError(String key) {
+ public static @Nullable String getSecretFormatError(@Nullable String key) {
return getTokenPartError(key);
}
// ------------------------------------------------------
// JSON parsing
- public static final JsonReader Reader = new JsonReader()
+ public static final @Nonnull JsonReader Reader = new JsonReader()
{
@Override
- public final DbxAppInfo read(JsonParser parser)
+ public final @Nonnull DbxAppInfo read(@Nonnull JsonParser parser)
throws IOException, JsonReadException
{
JsonLocation top = JsonReader.expectObjectStart(parser);
@@ -191,10 +192,10 @@ else if (fieldName.equals("host")) {
}
};
- public static final JsonReader KeyReader = new JsonReader()
+ public static final @Nonnull JsonReader KeyReader = new JsonReader()
{
@Override
- public String read(JsonParser parser) throws IOException, JsonReadException
+ public @Nonnull String read(@Nonnull JsonParser parser) throws IOException, JsonReadException
{
try {
String v = parser.getText();
@@ -211,10 +212,10 @@ public String read(JsonParser parser) throws IOException, JsonReadException
}
};
- public static final JsonReader SecretReader = new JsonReader()
+ public static final @Nonnull JsonReader SecretReader = new JsonReader()
{
@Override
- public String read(JsonParser parser) throws IOException, JsonReadException
+ public @Nonnull String read(@Nonnull JsonParser parser) throws IOException, JsonReadException
{
try {
String v = parser.getText();
@@ -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";
@@ -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;
@@ -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;
diff --git a/core/src/main/java/com/dropbox/core/DbxAuthFinish.java b/core/src/main/java/com/dropbox/core/DbxAuthFinish.java
index 6a661e0b7..4eebe0124 100644
--- a/core/src/main/java/com/dropbox/core/DbxAuthFinish.java
+++ b/core/src/main/java/com/dropbox/core/DbxAuthFinish.java
@@ -1,5 +1,7 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import com.dropbox.core.json.JsonReadException;
import com.dropbox.core.json.JsonReader;
import com.fasterxml.jackson.core.JsonLocation;
@@ -11,22 +13,21 @@
import static com.dropbox.core.util.StringUtil.jq;
-/*>>> import checkers.nullness.quals.Nullable; */
/**
* When you successfully complete the authorization process, the Dropbox server returns
* this information to you.
*/
public final class DbxAuthFinish {
- private final String accessToken;
- private final Long expiresIn;
- private final String refreshToken;
- private final String userId;
- private final String accountId;
- private final String teamId;
- private final /*@Nullable*/String urlState;
+ private final @Nonnull String accessToken;
+ private final @Nullable Long expiresIn;
+ private final @Nullable String refreshToken;
+ private final @Nonnull String userId;
+ private final @Nullable String accountId;
+ private final @Nullable String teamId;
+ private final @Nullable String urlState;
private long issueTime;
- private final String scope;
+ private final @Nullable String scope;
/**
* @param accessToken OAuth access token
@@ -35,7 +36,11 @@ public final class DbxAuthFinish {
* was passed
*/
@Deprecated
- public DbxAuthFinish(String accessToken, String userId, String accountId, String teamId, /*@Nullable*/String urlState) {
+ public DbxAuthFinish(@Nonnull String accessToken,
+ @Nonnull String userId,
+ @Nullable String accountId,
+ @Nullable String teamId,
+ @Nullable String urlState) {
this(accessToken, null, null, userId, teamId, accountId, urlState);
}
@@ -52,8 +57,13 @@ public DbxAuthFinish(String accessToken, String userId, String accountId, String
* @param urlState State data passed in to {@link DbxWebAuth#start} or {@code null} if no state
* was passed
*/
- public DbxAuthFinish(String accessToken, Long expiresIn, String refreshToken, String userId,
- String teamId, String accountId, /*@Nullable*/String urlState) {
+ public DbxAuthFinish(@Nonnull String accessToken,
+ @Nullable Long expiresIn,
+ @Nullable String refreshToken,
+ @Nonnull String userId,
+ @Nullable String teamId,
+ @Nullable String accountId,
+ @Nullable String urlState) {
this(accessToken, expiresIn, refreshToken, userId, teamId, accountId, urlState, null);
}
@@ -73,9 +83,14 @@ public DbxAuthFinish(String accessToken, Long expiresIn, String refreshToken, St
* API endpoints. To call one API endpoint you have to obtains the scope first otherwise you
* will get HTTP 401.
*/
- public DbxAuthFinish(String accessToken, Long expiresIn, String refreshToken, String userId,
- String teamId, String accountId, /*@Nullable*/String urlState, String
- scope) {
+ public DbxAuthFinish(@Nonnull String accessToken,
+ @Nullable Long expiresIn,
+ @Nullable String refreshToken,
+ @Nonnull String userId,
+ @Nullable String teamId,
+ @Nullable String accountId,
+ @Nullable String urlState,
+ @Nullable String scope) {
this.accessToken = accessToken;
this.expiresIn = expiresIn;
this.refreshToken = refreshToken;
@@ -93,7 +108,7 @@ public DbxAuthFinish(String accessToken, Long expiresIn, String refreshToken, St
*
* @return OAuth access token used for authorization with Dropbox servers
*/
- public String getAccessToken() {
+ public @Nonnull String getAccessToken() {
return accessToken;
}
@@ -106,7 +121,7 @@ public String getAccessToken() {
*
* @return OAuth access token used for authorization with Dropbox servers
*/
- public Long getExpiresAt() {
+ public @Nullable Long getExpiresAt() {
if (expiresIn == null) {
return null;
}
@@ -122,7 +137,7 @@ public Long getExpiresAt() {
*
* @return OAuth access token used for authorization with Dropbox servers
*/
- public String getRefreshToken() {
+ public @Nullable String getRefreshToken() {
return refreshToken;
}
@@ -132,7 +147,7 @@ public String getRefreshToken() {
*
* @return Dropbox user ID of user that approved your app for access to their account
*/
- public String getUserId() {
+ public @Nonnull String getUserId() {
return userId;
}
@@ -142,7 +157,7 @@ public String getUserId() {
*
* @return Dropbox account ID of user that approved your app for access to their account
*/
- public String getAccountId() {
+ public @Nullable String getAccountId() {
return accountId;
}
@@ -152,7 +167,7 @@ public String getAccountId() {
*
* @return Dropbox team ID of team's that approved your app for access to their account
*/
- public String getTeamId() {
+ public @Nullable String getTeamId() {
return teamId;
}
@@ -164,7 +179,7 @@ public String getTeamId() {
* API endpoints. To call one API endpoint you have to obtains the scope first otherwise you
* will get HTTP 401.
*/
- public String getScope() {
+ public @Nullable String getScope() {
return scope;
}
@@ -175,7 +190,7 @@ public String getScope() {
* @return state data passed into {@link DbxWebAuth#start}, or {@code null} if no state was
* passed
*/
- public /*@Nullable*/ String getUrlState() {
+ public @Nullable String getUrlState() {
return urlState;
}
@@ -192,7 +207,8 @@ void setIssueTime(long issueTime) {
*
* @param urlState Custom state passed into /oauth2/authorize
*/
- DbxAuthFinish withUrlState(/*@Nullable*/ String urlState) {
+ @Nonnull
+ DbxAuthFinish withUrlState(@Nullable String urlState) {
if (this.urlState != null) {
throw new IllegalStateException("Already have URL state.");
}
@@ -207,8 +223,8 @@ DbxAuthFinish withUrlState(/*@Nullable*/ String urlState) {
/**
* For JSON parsing.
*/
- public static final JsonReader Reader = new JsonReader() {
- public DbxAuthFinish read(JsonParser parser) throws IOException, JsonReadException {
+ public static final @Nonnull JsonReader Reader = new JsonReader() {
+ public @Nonnull DbxAuthFinish read(@Nonnull JsonParser parser) throws IOException, JsonReadException {
JsonLocation top = JsonReader.expectObjectStart(parser);
String accessToken = null;
@@ -281,9 +297,9 @@ else if (fieldName.equals("scope")) {
}
};
- public static final JsonReader BearerTokenTypeReader = new JsonReader() {
+ public static final @Nonnull JsonReader BearerTokenTypeReader = new JsonReader() {
@Override
- public String read(JsonParser parser) throws IOException, JsonReadException {
+ public @Nonnull String read(@Nonnull JsonParser parser) throws IOException, JsonReadException {
try {
String v = parser.getText();
if (!v.equals("Bearer") && !v.equals("bearer")) {
@@ -298,9 +314,9 @@ public String read(JsonParser parser) throws IOException, JsonReadException {
};
- public static final JsonReader AccessTokenReader = new JsonReader() {
+ public static final @Nonnull JsonReader AccessTokenReader = new JsonReader() {
@Override
- public String read(JsonParser parser) throws IOException, JsonReadException {
+ public @Nonnull String read(@Nonnull JsonParser parser) throws IOException, JsonReadException {
try {
String v = parser.getText();
String error = DbxAppInfo.getTokenPartError(v);
diff --git a/core/src/main/java/com/dropbox/core/DbxAuthInfo.java b/core/src/main/java/com/dropbox/core/DbxAuthInfo.java
index 7edb10185..e97c0ed9b 100644
--- a/core/src/main/java/com/dropbox/core/DbxAuthInfo.java
+++ b/core/src/main/java/com/dropbox/core/DbxAuthInfo.java
@@ -9,15 +9,17 @@
import com.fasterxml.jackson.core.JsonToken;
import java.io.IOException;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
/**
* Used by the example code to remember auth information.
*/
public final class DbxAuthInfo {
- private final String accessToken;
- private final Long expiresAt;
- private final String refreshToken;
- private final DbxHost host;
+ private final @Nonnull String accessToken;
+ private final @Nullable Long expiresAt;
+ private final @Nullable String refreshToken;
+ private final @Nonnull DbxHost host;
/**
* Creates a new instance with the given parameters.
@@ -25,7 +27,7 @@ public final class DbxAuthInfo {
* @param accessToken OAuth access token for authorization with Dropbox servers
* @param host Dropbox host configuration used to select Dropbox servers
*/
- public DbxAuthInfo(String accessToken, DbxHost host) {
+ public DbxAuthInfo(@Nonnull String accessToken, @Nonnull DbxHost host) {
this(accessToken, null, null, host);
}
@@ -38,7 +40,10 @@ public DbxAuthInfo(String accessToken, DbxHost host) {
* @param refreshToken Refresh token which can bu used to obtain new accessToken
* @param host Dropbox host configuration used to select Dropbox servers
*/
- public DbxAuthInfo(String accessToken, Long expiresAt, String refreshToken, DbxHost host) {
+ public DbxAuthInfo(@Nonnull String accessToken,
+ @Nullable Long expiresAt,
+ @Nullable String refreshToken,
+ @Nonnull DbxHost host) {
if (accessToken == null) throw new IllegalArgumentException("'accessToken' can't be null");
if (host == null) throw new IllegalArgumentException("'host' can't be null");
@@ -53,7 +58,7 @@ public DbxAuthInfo(String accessToken, Long expiresAt, String refreshToken, DbxH
*
* @return OAuth access token
*/
- public String getAccessToken() {
+ public @Nonnull String getAccessToken() {
return accessToken;
}
@@ -63,7 +68,7 @@ public String getAccessToken() {
*
* @return ExpiresAt in millisecond.
*/
- public Long getExpiresAt() {
+ public @Nullable Long getExpiresAt() {
return expiresAt;
}
@@ -73,7 +78,7 @@ public Long getExpiresAt() {
*
* @return Refresh Token.
*/
- public String getRefreshToken() {
+ public @Nullable String getRefreshToken() {
return refreshToken;
}
@@ -82,14 +87,14 @@ public String getRefreshToken() {
*
* @return Dropbox host configuration
*/
- public DbxHost getHost() {
+ public @Nonnull DbxHost getHost() {
return host;
}
- public static final JsonReader Reader = new JsonReader()
+ public static final @Nonnull JsonReader Reader = new JsonReader()
{
@Override
- public final DbxAuthInfo read(JsonParser parser)
+ public final @Nonnull DbxAuthInfo read(@Nonnull JsonParser parser)
throws IOException, JsonReadException
{
JsonLocation top = JsonReader.expectObjectStart(parser);
@@ -135,10 +140,10 @@ else if (fieldName.equals("access_token")) {
}
};
- public static final JsonWriter Writer = new JsonWriter()
+ public static final @Nonnull JsonWriter Writer = new JsonWriter()
{
@Override
- public void write(DbxAuthInfo authInfo, JsonGenerator g) throws IOException
+ public void write(@Nonnull DbxAuthInfo authInfo, @Nonnull JsonGenerator g) throws IOException
{
g.writeStartObject();
g.writeStringField("access_token", authInfo.accessToken);
diff --git a/core/src/main/java/com/dropbox/core/DbxDownloader.java b/core/src/main/java/com/dropbox/core/DbxDownloader.java
index ac52113f0..e3d23dc8d 100644
--- a/core/src/main/java/com/dropbox/core/DbxDownloader.java
+++ b/core/src/main/java/com/dropbox/core/DbxDownloader.java
@@ -8,6 +8,9 @@
import java.io.IOException;
import java.io.OutputStream;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* Class for handling download requests.
*
@@ -38,13 +41,13 @@
*
*/
public class DbxDownloader implements Closeable {
- private final R result;
- private final InputStream body;
- private final String contentType;
+ private final @Nullable R result;
+ private final @Nonnull InputStream body;
+ private final @Nullable String contentType;
private boolean closed;
- public DbxDownloader(R result, InputStream body, String contentType) {
+ public DbxDownloader(@Nullable R result, @Nonnull InputStream body, @Nullable String contentType) {
this.result = result;
this.body = body;
this.contentType = contentType;
@@ -52,7 +55,7 @@ public DbxDownloader(R result, InputStream body, String contentType) {
this.closed = false;
}
- public DbxDownloader(R result, InputStream body) {
+ public DbxDownloader(@Nullable R result, @Nonnull InputStream body) {
this(result, body, null);
}
@@ -64,7 +67,7 @@ public DbxDownloader(R result, InputStream body) {
*
* @return Response from server
*/
- public R getResult() {
+ public @Nullable R getResult() {
return result;
}
@@ -73,7 +76,7 @@ public R getResult() {
*
* @return the content type, or null if not known.
*/
- public String getContentType() {
+ public @Nullable String getContentType() {
return contentType;
}
@@ -87,7 +90,7 @@ public String getContentType() {
*
* @throws IllegalStateException if this downloader has already been closed (see {@link #close})
*/
- public InputStream getInputStream() {
+ public @Nonnull InputStream getInputStream() {
assertOpen();
return body;
}
@@ -120,7 +123,7 @@ public InputStream getInputStream() {
* @throws IOException if an error occurs writing the response body to the output stream.
* @throws IllegalStateException if this downloader has already been closed (see {@link #close})
*/
- public R download(OutputStream out) throws DbxException, IOException {
+ public @Nullable R download(@Nonnull OutputStream out) throws DbxException, IOException {
try {
IOUtil.copyStreamToStream(getInputStream(), out);
} catch (IOUtil.WriteException ex) {
@@ -146,7 +149,7 @@ public R download(OutputStream out) throws DbxException, IOException {
* @throws DbxException if an error occurs reading the response or response body.
* @throws IOException if an error occurs writing the response body to the output stream.
*/
- public R download(OutputStream out, IOUtil.ProgressListener progressListener)
+ public @Nullable R download(@Nonnull OutputStream out, @Nullable IOUtil.ProgressListener progressListener)
throws DbxException, IOException {
return download(new ProgressOutputStream(out, progressListener));
}
diff --git a/core/src/main/java/com/dropbox/core/DbxException.java b/core/src/main/java/com/dropbox/core/DbxException.java
index d485ab1c2..a98551b53 100644
--- a/core/src/main/java/com/dropbox/core/DbxException.java
+++ b/core/src/main/java/com/dropbox/core/DbxException.java
@@ -2,6 +2,9 @@
import java.io.IOException;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* The base exception thrown by Dropbox API calls. Normally, you'll need to do something specific
* for {@link InvalidAccessTokenException} and possibly for {@link RetryException}. The rest you
@@ -10,22 +13,22 @@
public class DbxException extends Exception {
private static final long serialVersionUID = 0L;
- private final String requestId;
+ private final @Nullable String requestId;
- public DbxException(String message) {
+ public DbxException(@Nullable String message) {
this(null, message);
}
- public DbxException(String requestId, String message) {
+ public DbxException(@Nullable String requestId, @Nullable String message) {
super(message);
this.requestId = requestId;
}
- public DbxException(String message, Throwable cause) {
+ public DbxException(@Nullable String message, @Nonnull Throwable cause) {
this(null, message, cause);
}
- public DbxException(String requestId, String message, Throwable cause) {
+ public DbxException(@Nullable String requestId, @Nullable String message, @Nonnull Throwable cause) {
super(message, cause);
this.requestId = requestId;
}
@@ -41,7 +44,7 @@ public DbxException(String requestId, String message, Throwable cause) {
* @return unique ID associated with the request that caused this exception, or {@code null} if
* one is not available.
*/
- public String getRequestId() {
+ public @Nullable String getRequestId() {
return requestId;
}
}
diff --git a/core/src/main/java/com/dropbox/core/DbxHost.java b/core/src/main/java/com/dropbox/core/DbxHost.java
index 684d88233..77d9b7968 100644
--- a/core/src/main/java/com/dropbox/core/DbxHost.java
+++ b/core/src/main/java/com/dropbox/core/DbxHost.java
@@ -1,5 +1,7 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import com.dropbox.core.json.JsonReadException;
import com.dropbox.core.json.JsonReader;
import com.dropbox.core.json.JsonWriter;
@@ -11,7 +13,6 @@
import java.io.IOException;
import java.util.Arrays;
-/*>>> import checkers.nullness.quals.Nullable; */
/**
* This is for mocking things out during testing. Most of the time you won't have to deal with
@@ -22,17 +23,17 @@ public final class DbxHost {
* The standard Dropbox hosts: "api.dropbox.com", "api-content.dropbox.com",
* and "www.dropbox.com"
*/
- public static final DbxHost DEFAULT = new DbxHost(
+ public static final @Nonnull DbxHost DEFAULT = new DbxHost(
"api.dropboxapi.com",
"content.dropboxapi.com",
"www.dropbox.com",
"notify.dropboxapi.com"
);
- private final String api;
- private final String content;
- private final String web;
- private final String notify;
+ private final @Nonnull String api;
+ private final @Nonnull String content;
+ private final @Nonnull String web;
+ private final @Nonnull String notify;
/**
* @param api main Dropbox API server host name
@@ -40,7 +41,7 @@ public final class DbxHost {
* @param web Dropbox web server host name
* @param notify Dropbox notification server host name
*/
- public DbxHost(String api, String content, String web, String notify) {
+ public DbxHost(@Nonnull String api, @Nonnull String content, @Nonnull String web, @Nonnull String notify) {
this.api = api;
this.content = content;
this.web = web;
@@ -53,7 +54,7 @@ public DbxHost(String api, String content, String web, String notify) {
*
* @return host name of main Dropbox API server
*/
- public String getApi() {
+ public @Nonnull String getApi() {
return api;
}
@@ -63,7 +64,7 @@ public String getApi() {
*
* @return host name of Dropbox API content server
*/
- public String getContent() {
+ public @Nonnull String getContent() {
return content;
}
@@ -73,7 +74,7 @@ public String getContent() {
*
* @return host name of Dropbox API web server used during user authorization
*/
- public String getWeb() {
+ public @Nonnull String getWeb() {
return web;
}
@@ -83,7 +84,7 @@ public String getWeb() {
*
* @return host name of Dropbox notification server used for longpolling
*/
- public String getNotify() {
+ public @Nonnull String getNotify() {
return notify;
}
@@ -93,7 +94,7 @@ public int hashCode() {
}
@Override
- public boolean equals(/*@Nullable*/Object obj) {
+ public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
} else if(obj instanceof DbxHost) {
@@ -107,13 +108,13 @@ public boolean equals(/*@Nullable*/Object obj) {
}
}
- private static DbxHost fromBaseHost(String s) {
+ private static @Nonnull DbxHost fromBaseHost(@Nonnull String s) {
return new DbxHost("api-" + s, "api-content-" + s, "meta-" + s, "api-notify-" + s);
}
- public static final JsonReader Reader = new JsonReader() {
+ public static final @Nonnull JsonReader Reader = new JsonReader() {
@Override
- public DbxHost read(JsonParser parser) throws IOException, JsonReadException {
+ public @Nonnull DbxHost read(@Nonnull JsonParser parser) throws IOException, JsonReadException {
JsonToken t = parser.getCurrentToken();
if (t == JsonToken.VALUE_STRING) {
String s = parser.getText();
@@ -168,7 +169,7 @@ else if (fieldName.equals("notify")) {
}
};
- private /*@Nullable*/String inferBaseHost() {
+ private @Nullable String inferBaseHost() {
if (web.startsWith("meta-") && api.startsWith("api-") && content.startsWith("api-content-") && notify.startsWith("api-notify-")) {
String webBase = web.substring("meta-".length());
String apiBase = api.substring("api-".length());
@@ -181,9 +182,9 @@ else if (fieldName.equals("notify")) {
return null;
}
- public static final JsonWriter Writer = new JsonWriter() {
+ public static final @Nonnull JsonWriter Writer = new JsonWriter() {
@Override
- public void write(DbxHost host, JsonGenerator g) throws IOException {
+ public void write(@Nonnull DbxHost host, @Nonnull JsonGenerator g) throws IOException {
String base = host.inferBaseHost();
if (base != null) {
g.writeString(base);
diff --git a/core/src/main/java/com/dropbox/core/DbxOAuth1AccessToken.java b/core/src/main/java/com/dropbox/core/DbxOAuth1AccessToken.java
index ee1ad2625..bf231eaef 100644
--- a/core/src/main/java/com/dropbox/core/DbxOAuth1AccessToken.java
+++ b/core/src/main/java/com/dropbox/core/DbxOAuth1AccessToken.java
@@ -1,19 +1,21 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+
/**
* Use with {@link DbxOAuth1Upgrader} to convert old OAuth 1 access tokens
* to OAuth 2 access tokens. This SDK doesn't support using OAuth 1 access
* tokens for regular API calls.
*/
public final class DbxOAuth1AccessToken {
- private final String key;
- private final String secret;
+ private final @Nonnull String key;
+ private final @Nonnull String secret;
/**
* @param key OAuth 1 access token key
* @param secret OAuth 2 access token secret
*/
- public DbxOAuth1AccessToken(String key, String secret) {
+ public DbxOAuth1AccessToken(@Nonnull String key, @Nonnull String secret) {
this.key = key;
this.secret = secret;
}
@@ -23,7 +25,7 @@ public DbxOAuth1AccessToken(String key, String secret) {
*
* @return OAuth 1 access token key
*/
- public String getKey() {
+ public @Nonnull String getKey() {
return key;
}
@@ -32,7 +34,7 @@ public String getKey() {
*
* @return OAuth 1 access token secret
*/
- public String getSecret() {
+ public @Nonnull String getSecret() {
return secret;
}
}
diff --git a/core/src/main/java/com/dropbox/core/DbxOAuth1Upgrader.java b/core/src/main/java/com/dropbox/core/DbxOAuth1Upgrader.java
index e772892e0..97c5d32ea 100644
--- a/core/src/main/java/com/dropbox/core/DbxOAuth1Upgrader.java
+++ b/core/src/main/java/com/dropbox/core/DbxOAuth1Upgrader.java
@@ -15,6 +15,8 @@
import java.net.URLEncoder;
import java.util.ArrayList;
+import javax.annotation.Nonnull;
+
/**
* Lets you convert OAuth 1 access tokens to OAuth 2 access tokens. First call {@link
* #createOAuth2AccessToken} to get an OAuth 2 access token. If that succeeds, call {@link
@@ -22,14 +24,14 @@
*/
public final class DbxOAuth1Upgrader
{
- private final DbxRequestConfig requestConfig;
- private final DbxAppInfo appInfo;
+ private final @Nonnull DbxRequestConfig requestConfig;
+ private final @Nonnull DbxAppInfo appInfo;
/**
* @param appInfo
* Your application's Dropbox API information (the app key and secret).
*/
- public DbxOAuth1Upgrader(DbxRequestConfig requestConfig, DbxAppInfo appInfo)
+ public DbxOAuth1Upgrader(@Nonnull DbxRequestConfig requestConfig, @Nonnull DbxAppInfo appInfo)
{
if (requestConfig == null) throw new IllegalArgumentException("'requestConfig' is null");
if (appInfo == null) throw new IllegalArgumentException("'appInfo' is null");
@@ -42,7 +44,7 @@ public DbxOAuth1Upgrader(DbxRequestConfig requestConfig, DbxAppInfo appInfo)
* Given an existing active OAuth 1 access token, make a Dropbox API call to get a new OAuth 2
* access token that represents the same user and app.
*/
- public String createOAuth2AccessToken(DbxOAuth1AccessToken token)
+ public @Nonnull String createOAuth2AccessToken(@Nonnull DbxOAuth1AccessToken token)
throws DbxException
{
if (token == null) throw new IllegalArgumentException("'token' can't be null");
@@ -55,7 +57,7 @@ public String createOAuth2AccessToken(DbxOAuth1AccessToken token)
getHeaders(token),
new DbxRequestUtil.ResponseHandler() {
@Override
- public String handle(HttpRequestor.Response response) throws DbxException {
+ public @Nonnull String handle(@Nonnull HttpRequestor.Response response) throws DbxException {
if (response.getStatusCode() != 200) throw DbxRequestUtil.unexpectedStatus(response);
return DbxRequestUtil.readJsonFromResponse(ResponseReader, response);
}
@@ -66,7 +68,7 @@ public String handle(HttpRequestor.Response response) throws DbxException {
/**
* Tell the Dropbox API server to disable an OAuth 1 access token.
*/
- public void disableOAuth1AccessToken(DbxOAuth1AccessToken token)
+ public void disableOAuth1AccessToken(@Nonnull DbxOAuth1AccessToken token)
throws DbxException
{
if (token == null) throw new IllegalArgumentException("'token' can't be null");
@@ -79,7 +81,7 @@ public void disableOAuth1AccessToken(DbxOAuth1AccessToken token)
getHeaders(token),
new DbxRequestUtil.ResponseHandler() {
@Override
- public Void handle(HttpRequestor.Response response) throws DbxException {
+ public Void handle(@Nonnull HttpRequestor.Response response) throws DbxException {
if (response.getStatusCode() != 200) throw DbxRequestUtil.unexpectedStatus(response);
return null;
}
@@ -87,24 +89,29 @@ public Void handle(HttpRequestor.Response response) throws DbxException {
);
}
- private ArrayList getHeaders(DbxOAuth1AccessToken token)
+ private @Nonnull ArrayList getHeaders(@Nonnull DbxOAuth1AccessToken token)
{
ArrayList headers = new ArrayList(1);
headers.add(new HttpRequestor.Header("Authorization", buildOAuth1Header(token)));
return headers;
}
- private String buildOAuth1Header(DbxOAuth1AccessToken token)
+ private @Nonnull String buildOAuth1Header(@Nonnull DbxOAuth1AccessToken token)
{
+ String appSecret = this.appInfo.getSecret();
+ if (appSecret == null) {
+ throw new IllegalStateException("OAuth 1 token upgrade requires an app secret.");
+ }
+
StringBuilder buf = new StringBuilder();
buf.append("OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\"");
buf.append(", oauth_consumer_key=\"").append(encode(this.appInfo.getKey())).append("\"");
buf.append(", oauth_token=\"").append(encode(token.getKey())).append("\"");
- buf.append(", oauth_signature=\"").append(encode(this.appInfo.getSecret())).append("&").append(encode(token.getSecret())).append("\"");
+ buf.append(", oauth_signature=\"").append(encode(appSecret)).append("&").append(encode(token.getSecret())).append("\"");
return buf.toString();
}
- private static String encode(String s)
+ private static @Nonnull String encode(@Nonnull String s)
{
try {
return URLEncoder.encode(s, "UTF-8");
@@ -117,9 +124,9 @@ private static String encode(String s)
/**
* For JSON parsing.
*/
- public static final JsonReader ResponseReader = new JsonReader()
+ public static final @Nonnull JsonReader ResponseReader = new JsonReader()
{
- public String read(JsonParser parser) throws IOException, JsonReadException
+ public @Nonnull String read(@Nonnull JsonParser parser) throws IOException, JsonReadException
{
JsonLocation top = JsonReader.expectObjectStart(parser);
diff --git a/core/src/main/java/com/dropbox/core/DbxPKCEManager.java b/core/src/main/java/com/dropbox/core/DbxPKCEManager.java
index bd9cbcd32..7cdf9c1a1 100644
--- a/core/src/main/java/com/dropbox/core/DbxPKCEManager.java
+++ b/core/src/main/java/com/dropbox/core/DbxPKCEManager.java
@@ -13,6 +13,9 @@
import java.util.HashMap;
import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import static com.dropbox.core.util.StringUtil.urlSafeBase64Encode;
/**
@@ -23,15 +26,15 @@
* @see https://tools.ietf.org/html/rfc7636
*/
public class DbxPKCEManager {
- public static final String CODE_CHALLENGE_METHODS = "S256";
+ public static final @Nonnull String CODE_CHALLENGE_METHODS = "S256";
public static final int CODE_VERIFIER_SIZE = 128;
private static final SecureRandom RAND = new SecureRandom();
- private static final String CODE_VERIFIER_CHAR_SET =
+ private static final @Nonnull String CODE_VERIFIER_CHAR_SET =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";
- private String codeVerifier;
- private String codeChallenge;
+ private @Nonnull String codeVerifier;
+ private @Nonnull String codeChallenge;
/**
* This class has state. Each instance has a randomly generated codeVerifier in it. Just
@@ -43,11 +46,12 @@ public DbxPKCEManager() {
this.codeChallenge = generateCodeChallenge(this.codeVerifier);
}
- public DbxPKCEManager(String codeVerifier) {
+ public DbxPKCEManager(@Nonnull String codeVerifier) {
this.codeVerifier = codeVerifier;
this.codeChallenge = generateCodeChallenge(this.codeVerifier);
}
+ @Nonnull
String generateCodeVerifier() {
StringBuilder sb = new StringBuilder();
@@ -58,7 +62,7 @@ String generateCodeVerifier() {
return sb.toString();
}
- static String generateCodeChallenge(String codeVerifier) {
+ static @Nonnull String generateCodeChallenge(@Nonnull String codeVerifier) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] signiture = digest.digest(codeVerifier.getBytes("US-ASCII"));
@@ -73,14 +77,14 @@ static String generateCodeChallenge(String codeVerifier) {
/**
* @return The randomly generate code verifier in this instance.
*/
- public String getCodeVerifier() {
+ public @Nonnull String getCodeVerifier() {
return this.codeVerifier;
}
/**
* @return The code challenge, which is a hashed code verifier.
*/
- public String getCodeChallenge() {
+ public @Nonnull String getCodeChallenge() {
return this.codeChallenge;
}
@@ -96,11 +100,11 @@ public String getCodeChallenge() {
* refresh token.
* @throws DbxException If reqeust is invalid, or code expired, or server error.
*/
- public DbxAuthFinish makeTokenRequest(DbxRequestConfig requestConfig,
- String oauth2Code,
- String appKey,
- String redirectUri,
- DbxHost host) throws DbxException {
+ public @Nonnull DbxAuthFinish makeTokenRequest(@Nonnull DbxRequestConfig requestConfig,
+ @Nonnull String oauth2Code,
+ @Nonnull String appKey,
+ @Nullable String redirectUri,
+ @Nonnull DbxHost host) throws DbxException {
Map params = new HashMap();
params.put("grant_type", "authorization_code");
params.put("code", oauth2Code);
@@ -121,7 +125,7 @@ public DbxAuthFinish makeTokenRequest(DbxRequestConfig requestConfig,
null,
new DbxRequestUtil.ResponseHandler() {
@Override
- public DbxAuthFinish handle(HttpRequestor.Response response) throws DbxException {
+ public @Nonnull DbxAuthFinish handle(@Nonnull HttpRequestor.Response response) throws DbxException {
if (response.getStatusCode() != 200) {
throw DbxRequestUtil.unexpectedStatus(response);
}
diff --git a/core/src/main/java/com/dropbox/core/DbxPKCEWebAuth.java b/core/src/main/java/com/dropbox/core/DbxPKCEWebAuth.java
index 1e13029ac..6c42f6d55 100644
--- a/core/src/main/java/com/dropbox/core/DbxPKCEWebAuth.java
+++ b/core/src/main/java/com/dropbox/core/DbxPKCEWebAuth.java
@@ -11,6 +11,9 @@
import java.util.HashMap;
import java.util.Map;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import static com.dropbox.core.util.StringUtil.urlSafeBase64Encode;
/**
@@ -38,10 +41,10 @@
* new dropbox oauth guide
*/
public class DbxPKCEWebAuth {
- private final DbxRequestConfig requestConfig;
- private final DbxAppInfo appInfo;
- private final DbxWebAuth dbxWebAuth;
- private final DbxPKCEManager dbxPKCEManager;
+ private final @Nonnull DbxRequestConfig requestConfig;
+ private final @Nonnull DbxAppInfo appInfo;
+ private final @Nonnull DbxWebAuth dbxWebAuth;
+ private final @Nonnull DbxPKCEManager dbxPKCEManager;
private boolean started;
private boolean consumed;
@@ -54,7 +57,7 @@ public class DbxPKCEWebAuth {
*
* @throws IllegalStateException if appInfo contains app secret.
*/
- public DbxPKCEWebAuth(DbxRequestConfig requestConfig, DbxAppInfo appInfo) {
+ public DbxPKCEWebAuth(@Nonnull DbxRequestConfig requestConfig, @Nonnull DbxAppInfo appInfo) {
if (appInfo.hasSecret()) {
throw new IllegalStateException("PKCE cdoe flow doesn't require app secret, if you " +
"decide to embed it in your app, please use regular DbxWebAuth instead.");
@@ -88,7 +91,7 @@ public DbxPKCEWebAuth(DbxRequestConfig requestConfig, DbxAppInfo appInfo) {
* @return Authorization URL of website user can use to authorize your app.
*
*/
- public String authorize(DbxWebAuth.Request request) {
+ public @Nonnull String authorize(@Nonnull DbxWebAuth.Request request) {
if (consumed) {
throw new IllegalStateException("This DbxPKCEWebAuth instance has been consumed " +
"already. To start a new PKCE OAuth flow, please create a new instance.");
@@ -112,7 +115,7 @@ public String authorize(DbxWebAuth.Request request) {
* URL, or if an error occurs communicating with Dropbox.
* @see DbxWebAuth#finishFromCode(String)
*/
- public DbxAuthFinish finishFromCode(String code) throws DbxException {
+ public @Nonnull DbxAuthFinish finishFromCode(@Nonnull String code) throws DbxException {
return finish(code, null, null);
}
@@ -134,18 +137,22 @@ public DbxAuthFinish finishFromCode(String code) throws DbxException {
* @throws DbxException if the instance is not the same one used to generate authorization
* URL, or if an error occurs communicating with Dropbox.
*/
- public DbxAuthFinish finishFromRedirect(String redirectUri,
- DbxSessionStore sessionStore,
- Map params)
+ public @Nonnull DbxAuthFinish finishFromRedirect(@Nonnull String redirectUri,
+ @Nonnull DbxSessionStore sessionStore,
+ @Nonnull Map params)
throws DbxException, DbxWebAuth.BadRequestException, DbxWebAuth.BadStateException,
DbxWebAuth.CsrfException, DbxWebAuth.NotApprovedException, DbxWebAuth.ProviderException {
- String strippedState = DbxWebAuth.validateRedirectUri(redirectUri, sessionStore, params);
+ @Nullable String strippedState = DbxWebAuth.validateRedirectUri(redirectUri, sessionStore, params);
String code = DbxWebAuth.getParam(params, "code");
+ if (code == null) {
+ throw new DbxWebAuth.BadRequestException("Missing required parameter: \"code\".");
+ }
return finish(code, redirectUri, strippedState);
}
- DbxAuthFinish finish(String code, String redirectUri, final String state) throws DbxException {
+ @Nonnull
+ DbxAuthFinish finish(@Nonnull String code, @Nullable String redirectUri, final @Nullable String state) throws DbxException {
if (code == null) throw new NullPointerException("code");
if (!this.started) {
throw new IllegalStateException("Must initialize the PKCE flow by calling authorize " +
diff --git a/core/src/main/java/com/dropbox/core/DbxRequestConfig.java b/core/src/main/java/com/dropbox/core/DbxRequestConfig.java
index 54eec5c3e..4da3a5478 100644
--- a/core/src/main/java/com/dropbox/core/DbxRequestConfig.java
+++ b/core/src/main/java/com/dropbox/core/DbxRequestConfig.java
@@ -1,23 +1,27 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.util.Locale;
import com.dropbox.core.http.HttpRequestor;
import com.dropbox.core.http.StandardHttpRequestor;
-/*>>> import checkers.nullness.quals.Nullable; */
/**
* A grouping of a few configuration parameters for how we should make requests to the
* Dropbox servers.
*/
public class DbxRequestConfig {
- private final String clientIdentifier;
- private final /*@Nullable*/String userLocale;
- private final HttpRequestor httpRequestor;
+ private final @Nonnull String clientIdentifier;
+ private final @Nullable String userLocale;
+ private final @Nonnull HttpRequestor httpRequestor;
private final int maxRetries;
- private DbxRequestConfig(String clientIdentifier, /*@Nullable*/ String userLocale, HttpRequestor httpRequestor, int maxRetries) {
+ private DbxRequestConfig(@Nonnull String clientIdentifier,
+ @Nullable String userLocale,
+ @Nonnull HttpRequestor httpRequestor,
+ int maxRetries) {
if (clientIdentifier == null) throw new NullPointerException("clientIdentifier");
if (httpRequestor == null) throw new NullPointerException("httpRequestor");
if (maxRetries < 0) throw new IllegalArgumentException("maxRetries");
@@ -33,7 +37,7 @@ private DbxRequestConfig(String clientIdentifier, /*@Nullable*/ String userLocal
*
* @param clientIdentifier see {@link #getClientIdentifier}
*/
- public DbxRequestConfig(String clientIdentifier) {
+ public DbxRequestConfig(@Nonnull String clientIdentifier) {
this(clientIdentifier, null);
}
@@ -46,7 +50,7 @@ public DbxRequestConfig(String clientIdentifier) {
* @deprecated Use {@link #newBuilder} to customize configuration
*/
@Deprecated
- public DbxRequestConfig(String clientIdentifier, /*@Nullable*/ String userLocale) {
+ public DbxRequestConfig(@Nonnull String clientIdentifier, @Nullable String userLocale) {
this(clientIdentifier, userLocale, StandardHttpRequestor.INSTANCE);
}
@@ -60,7 +64,9 @@ public DbxRequestConfig(String clientIdentifier, /*@Nullable*/ String userLocale
* @deprecated Use {@link #newBuilder} to customize configuration
*/
@Deprecated
- public DbxRequestConfig(String clientIdentifier, /*@Nullable*/ String userLocale, HttpRequestor httpRequestor) {
+ public DbxRequestConfig(@Nonnull String clientIdentifier,
+ @Nullable String userLocale,
+ @Nonnull HttpRequestor httpRequestor) {
this(clientIdentifier, userLocale, httpRequestor, 0);
}
@@ -82,7 +88,7 @@ public DbxRequestConfig(String clientIdentifier, /*@Nullable*/ String userLocale
* debugging things later.
*
*/
- public String getClientIdentifier() {
+ public @Nonnull String getClientIdentifier() {
return clientIdentifier;
}
@@ -106,7 +112,7 @@ public String getClientIdentifier() {
* to the user's configured locale setting.
*
*/
- public String getUserLocale() {
+ public @Nullable String getUserLocale() {
return userLocale;
}
@@ -114,7 +120,7 @@ public String getUserLocale() {
* Returns the {@link HttpRequestor} you passed in when constructing this object, which
* defaults to {@link StandardHttpRequestor#INSTANCE}.
*/
- public HttpRequestor getHttpRequestor() {
+ public @Nonnull HttpRequestor getHttpRequestor() {
return httpRequestor;
}
@@ -162,7 +168,7 @@ public int getMaxRetries() {
*
* @return builder configured to build a copy of this instance
*/
- public Builder copy() {
+ public @Nonnull Builder copy() {
return new Builder(clientIdentifier, userLocale, httpRequestor, maxRetries);
}
@@ -172,13 +178,13 @@ public Builder copy() {
*
* @param clientIdentifier see {@link #getClientIdentifier}
*/
- public static Builder newBuilder(String clientIdentifier) {
+ public static @Nonnull Builder newBuilder(@Nonnull String clientIdentifier) {
if (clientIdentifier == null) throw new NullPointerException("clientIdentifier");
return new Builder(clientIdentifier);
}
// Available in Java 7, but not in Java 6. Do a hacky version of it here.
- private static String toLanguageTag(Locale locale) {
+ private static @Nullable String toLanguageTag(@Nullable Locale locale) {
if (locale == null) {
return null;
}
@@ -197,7 +203,7 @@ private static String toLanguageTag(Locale locale) {
// APIv1 accepts Locale.toString() formatted locales (e.g. 'en_US'), but APIv2 will return an
// error if the locale is not in proper Language Tag format. Attempt to convert old locale
// formats to the new one.
- private static String toLanguageTag(String locale) {
+ private static @Nullable String toLanguageTag(@Nullable String locale) {
if (locale == null) {
return null;
}
@@ -226,15 +232,15 @@ private static String toLanguageTag(String locale) {
* Builder for {@link DbxRequestConfig}.
*/
public static final class Builder {
- private final String clientIdentifier;
+ private final @Nonnull String clientIdentifier;
- private /*@Nullable*/ String userLocale;
- private HttpRequestor httpRequestor;
+ private @Nullable String userLocale;
+ private @Nonnull HttpRequestor httpRequestor;
private int maxRetries;
- private Builder(String clientIdentifier,
- /*@Nullable*/ String userLocale,
- HttpRequestor httpRequestor,
+ private Builder(@Nonnull String clientIdentifier,
+ @Nullable String userLocale,
+ @Nonnull HttpRequestor httpRequestor,
int maxRetries) {
this.clientIdentifier = clientIdentifier;
this.userLocale = userLocale;
@@ -242,7 +248,7 @@ private Builder(String clientIdentifier,
this.maxRetries = maxRetries;
}
- private Builder(String clientIdentifier) {
+ private Builder(@Nonnull String clientIdentifier) {
this.clientIdentifier = clientIdentifier;
this.userLocale = null;
@@ -262,7 +268,7 @@ private Builder(String clientIdentifier) {
*
* @return this builder
*/
- public Builder withUserLocale(/*@Nullable*/ String userLocale) {
+ public @Nonnull Builder withUserLocale(@Nullable String userLocale) {
this.userLocale = userLocale;
return this;
}
@@ -276,7 +282,7 @@ public Builder withUserLocale(/*@Nullable*/ String userLocale) {
*
* @return this builder
*/
- public Builder withUserLocaleFromPreferences() {
+ public @Nonnull Builder withUserLocaleFromPreferences() {
this.userLocale = null;
return this;
}
@@ -292,7 +298,7 @@ public Builder withUserLocaleFromPreferences() {
*
* @return this builder
*/
- public Builder withUserLocaleFrom(/*@Nullable*/ Locale userLocale) { // not named withUserLocale because of ambiguous calls when passing 'null'
+ public @Nonnull Builder withUserLocaleFrom(@Nullable Locale userLocale) { // not named withUserLocale because of ambiguous calls when passing 'null'
this.userLocale = toLanguageTag(userLocale);
return this;
}
@@ -306,7 +312,7 @@ public Builder withUserLocaleFrom(/*@Nullable*/ Locale userLocale) { // not name
*
* @return this builder
*/
- public Builder withHttpRequestor(HttpRequestor httpRequestor) {
+ public @Nonnull Builder withHttpRequestor(@Nonnull HttpRequestor httpRequestor) {
if (httpRequestor == null) throw new NullPointerException("httpRequestor");
this.httpRequestor = httpRequestor;
return this;
@@ -324,7 +330,7 @@ public Builder withHttpRequestor(HttpRequestor httpRequestor) {
*
* @return this builder
*/
- public Builder withAutoRetryEnabled() {
+ public @Nonnull Builder withAutoRetryEnabled() {
return withAutoRetryEnabled(3);
}
@@ -338,7 +344,7 @@ public Builder withAutoRetryEnabled() {
*
* @see #withAutoRetryEnabled
*/
- public Builder withAutoRetryDisabled() {
+ public @Nonnull Builder withAutoRetryDisabled() {
this.maxRetries = 0;
return this;
}
@@ -365,7 +371,7 @@ public Builder withAutoRetryDisabled() {
*
* @throws IllegalArgumentException if {@code maxRetries} is not positive.
*/
- public Builder withAutoRetryEnabled(int maxRetries) {
+ public @Nonnull Builder withAutoRetryEnabled(int maxRetries) {
if (maxRetries <= 0) throw new IllegalArgumentException("maxRetries must be positive");
this.maxRetries = maxRetries;
return this;
@@ -377,7 +383,7 @@ public Builder withAutoRetryEnabled(int maxRetries) {
*
* @return new {@code DbxRequestConfig} instance.
*/
- public DbxRequestConfig build() {
+ public @Nonnull DbxRequestConfig build() {
return new DbxRequestConfig(clientIdentifier, userLocale, httpRequestor, maxRetries);
}
}
diff --git a/core/src/main/java/com/dropbox/core/DbxRequestUtil.java b/core/src/main/java/com/dropbox/core/DbxRequestUtil.java
index 3f3df6d81..725dddf5c 100644
--- a/core/src/main/java/com/dropbox/core/DbxRequestUtil.java
+++ b/core/src/main/java/com/dropbox/core/DbxRequestUtil.java
@@ -1,5 +1,7 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
@@ -32,14 +34,13 @@
import static com.dropbox.core.util.StringUtil.jq;
import static com.dropbox.core.util.LangUtil.mkAssert;
-/*>>> import checkers.nullness.quals.Nullable; */
public final class DbxRequestUtil {
private static final Random RAND = new Random();
- public static DbxGlobalCallbackFactory sharedCallbackFactory;
+ public static @Nullable DbxGlobalCallbackFactory sharedCallbackFactory;
- public static String encodeUrlParam(String s) {
+ public static @Nonnull String encodeUrlParam(@Nonnull String s) {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException ex) {
@@ -47,14 +48,14 @@ public static String encodeUrlParam(String s) {
}
}
- public static String buildUrlWithParams(/*@Nullable*/String userLocale,
- String host,
- String path,
- /*@Nullable*/String/*@Nullable*/[] params) {
+ public static @Nonnull String buildUrlWithParams(@Nullable String userLocale,
+ @Nonnull String host,
+ @Nonnull String path,
+ @Nullable String[] params) {
return buildUri(host, path) + "?" + encodeUrlParams(userLocale, params);
}
- public static String [] toParamsArray(Map params) {
+ public static @Nonnull String [] toParamsArray(@Nonnull Map params) {
String [] arr = new String[2 * params.size()];
int i = 0;
for (Map.Entry entry : params.entrySet()) {
@@ -65,7 +66,7 @@ public static String buildUrlWithParams(/*@Nullable*/String userLocale,
return arr;
}
- public static String buildUri(String host, String path) {
+ public static @Nonnull String buildUri(@Nonnull String host, @Nonnull String path) {
try {
return new URI("https", host, "/" + path, null).toASCIIString();
}
@@ -74,8 +75,8 @@ public static String buildUri(String host, String path) {
}
}
- private static String encodeUrlParams(/*@Nullable*/String userLocale,
- /*@Nullable*/String/*@Nullable*/[] params) {
+ private static @Nonnull String encodeUrlParams(@Nullable String userLocale,
+ @Nullable String[] params) {
StringBuilder buf = new StringBuilder();
String sep = "";
if (userLocale != null) {
@@ -104,7 +105,8 @@ private static String encodeUrlParams(/*@Nullable*/String userLocale,
return buf.toString();
}
- public static List addAuthHeader(/*@Nullable*/List headers, String accessToken) {
+ public static @Nonnull List addAuthHeader(@Nullable List headers,
+ @Nonnull String accessToken) {
if (accessToken == null) throw new NullPointerException("accessToken");
if (headers == null) headers = new ArrayList();
@@ -112,7 +114,8 @@ public static List addAuthHeader(/*@Nullable*/List addSelectUserHeader(/*@Nullable*/List headers, String memberId) {
+ public static @Nonnull List addSelectUserHeader(@Nullable List headers,
+ @Nonnull String memberId) {
if (memberId == null) throw new NullPointerException("memberId");
if (headers == null) headers = new ArrayList();
@@ -120,7 +123,8 @@ public static List addSelectUserHeader(/*@Nullable*/List addSelectAdminHeader(/*@Nullable*/List headers, String adminId) {
+ public static @Nonnull List addSelectAdminHeader(@Nullable List headers,
+ @Nonnull String adminId) {
if (adminId == null) throw new NullPointerException("adminId");
if (headers == null) headers = new ArrayList();
@@ -128,7 +132,9 @@ public static List addSelectAdminHeader(/*@Nullable*/List<
return headers;
}
- public static List addBasicAuthHeader(/*@Nullable*/List headers, String username, String password) {
+ public static @Nonnull List addBasicAuthHeader(@Nullable List headers,
+ @Nonnull String username,
+ @Nonnull String password) {
if (username == null) throw new NullPointerException("username");
if (password == null) throw new NullPointerException("password");
if (headers == null) headers = new ArrayList();
@@ -139,17 +145,18 @@ public static List addBasicAuthHeader(/*@Nullable*/List addUserAgentHeader(
- /*@Nullable*/List headers,
- DbxRequestConfig requestConfig,
- String sdkUserAgentIdentifier
+ public static @Nonnull List addUserAgentHeader(
+ @Nullable List headers,
+ @Nonnull DbxRequestConfig requestConfig,
+ @Nonnull String sdkUserAgentIdentifier
) {
if (headers == null) headers = new ArrayList();
headers.add(buildUserAgentHeader(requestConfig, sdkUserAgentIdentifier));
return headers;
}
- public static List addUserLocaleHeader(/*@Nullable*/List headers, DbxRequestConfig requestConfig) {
+ public static @Nullable List addUserLocaleHeader(@Nullable List headers,
+ @Nonnull DbxRequestConfig requestConfig) {
if (requestConfig.getUserLocale() == null) {
return headers;
}
@@ -159,11 +166,13 @@ public static List addUserLocaleHeader(/*@Nullable*/List addPathRootHeader(/*@Nullable*/List headers, PathRoot pathRoot) {
+ public static @Nullable List addPathRootHeader(@Nullable List headers,
+ @Nullable PathRoot pathRoot) {
if (pathRoot == null) {
return headers;
}
@@ -173,7 +182,7 @@ public static List addPathRootHeader(/*@Nullable*/List removeAuthHeader(/*@Nullable*/List headers) {
+ public static @Nonnull List removeAuthHeader(@Nullable List headers) {
if (headers == null) {
return new ArrayList();
}
@@ -193,13 +202,13 @@ public static List removeAuthHeader(/*@Nullable*/List headers)
+ public static @Nonnull HttpRequestor.Response startGet(@Nonnull DbxRequestConfig requestConfig,
+ @Nonnull String accessToken,
+ @Nonnull String sdkUserAgentIdentifier,
+ @Nonnull String host,
+ @Nonnull String path,
+ @Nullable String[] params,
+ @Nullable List headers)
throws NetworkIOException {
headers = copyHeaders(headers);
headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier);
@@ -217,12 +226,12 @@ public static HttpRequestor.Response startGet(DbxRequestConfig requestConfig,
/**
* Convenience function for making HTTP PUT requests.
*/
- public static HttpRequestor.Uploader startPut(DbxRequestConfig requestConfig,
- String accessToken,
- String sdkUserAgentIdentifier,
- String host, String path,
- /*@Nullable*/String/*@Nullable*/[] params,
- /*@Nullable*/List headers)
+ public static @Nonnull HttpRequestor.Uploader startPut(@Nonnull DbxRequestConfig requestConfig,
+ @Nonnull String accessToken,
+ @Nonnull String sdkUserAgentIdentifier,
+ @Nonnull String host, @Nonnull String path,
+ @Nullable String[] params,
+ @Nullable List headers)
throws NetworkIOException {
headers = copyHeaders(headers);
headers = addUserAgentHeader(headers, requestConfig, sdkUserAgentIdentifier);
@@ -240,12 +249,12 @@ public static HttpRequestor.Uploader startPut(DbxRequestConfig requestConfig,
/**
* Convenience function for making HTTP POST requests.
*/
- public static HttpRequestor.Response startPostNoAuth(DbxRequestConfig requestConfig,
- String sdkUserAgentIdentifier,
- String host,
- String path,
- /*@Nullable*/String/*@Nullable*/[] params,
- /*@Nullable*/List headers)
+ public static @Nonnull HttpRequestor.Response startPostNoAuth(@Nonnull DbxRequestConfig requestConfig,
+ @Nonnull String sdkUserAgentIdentifier,
+ @Nonnull String host,
+ @Nonnull String path,
+ @Nullable String[] params,
+ @Nullable List headers)
throws NetworkIOException {
byte[] encodedParams = StringUtil.stringToUtf8(encodeUrlParams(requestConfig.getUserLocale(), params));
@@ -259,12 +268,12 @@ public static HttpRequestor.Response startPostNoAuth(DbxRequestConfig requestCon
/**
* Convenience function for making HTTP POST requests. Like startPostNoAuth but takes byte[] instead of params.
*/
- public static HttpRequestor.Response startPostRaw(DbxRequestConfig requestConfig,
- String sdkUserAgentIdentifier,
- String host,
- String path,
- byte[] body,
- /*@Nullable*/List headers)
+ public static @Nonnull HttpRequestor.Response startPostRaw(@Nonnull DbxRequestConfig requestConfig,
+ @Nonnull String sdkUserAgentIdentifier,
+ @Nonnull String host,
+ @Nonnull String path,
+ @Nonnull byte[] body,
+ @Nullable List headers)
throws NetworkIOException {
String uri = buildUri(host, path);
@@ -285,7 +294,7 @@ public static HttpRequestor.Response startPostRaw(DbxRequestConfig requestConfig
}
}
- private static List copyHeaders(List headers) {
+ private static @Nonnull List copyHeaders(@Nullable List headers) {
if (headers == null) {
return new ArrayList();
} else {
@@ -293,7 +302,7 @@ private static List copyHeaders(List
}
}
- public static byte[] loadErrorBody(HttpRequestor.Response response)
+ public static @Nonnull byte[] loadErrorBody(@Nonnull HttpRequestor.Response response)
throws NetworkIOException {
if (response.getBody() == null) {
return new byte[0];
@@ -308,7 +317,7 @@ public static byte[] loadErrorBody(HttpRequestor.Response response)
}
- public static String parseErrorBody(String requestId, int statusCode, byte[] body)
+ public static @Nonnull String parseErrorBody(@Nullable String requestId, int statusCode, @Nonnull byte[] body)
throws BadResponseException {
// Read the error message from the body.
// TODO: Get charset from the HTTP Content-Type header. It's wrong to just assume UTF-8.
@@ -320,11 +329,11 @@ public static String parseErrorBody(String requestId, int statusCode, byte[] bod
}
}
- public static DbxException unexpectedStatus(HttpRequestor.Response response) throws NetworkIOException, BadResponseException {
+ public static @Nonnull DbxException unexpectedStatus(@Nonnull HttpRequestor.Response response) throws NetworkIOException, BadResponseException {
return DbxRequestUtil.unexpectedStatus(response, null);
}
- public static DbxException unexpectedStatus(HttpRequestor.Response response, String userId)
+ public static @Nonnull DbxException unexpectedStatus(@Nonnull HttpRequestor.Response response, @Nullable String userId)
throws NetworkIOException, BadResponseException {
String requestId = getRequestId(response);
@@ -426,13 +435,15 @@ public static DbxException unexpectedStatus(HttpRequestor.Response response, Str
return networkError;
}
- private static String messageFromResponse(HttpRequestor.Response response, String requestId) throws NetworkIOException, BadResponseException {
+ private static @Nonnull String messageFromResponse(@Nonnull HttpRequestor.Response response,
+ @Nullable String requestId) throws NetworkIOException, BadResponseException {
byte[] body = loadErrorBody(response);
String message = parseErrorBody(requestId, response.getStatusCode(), body);
return message;
}
- public static T readJsonFromResponse(JsonReader reader, HttpRequestor.Response response)
+ public static @Nullable T readJsonFromResponse(@Nonnull JsonReader reader,
+ @Nonnull HttpRequestor.Response response)
throws BadResponseException, NetworkIOException {
try {
return reader.readFully(response.getBody());
@@ -444,75 +455,73 @@ public static T readJsonFromResponse(JsonReader reader, HttpRequestor.Res
}
}
- public static T readJsonFromErrorMessage(StoneSerializer serializer, String message, String requestId)
+ public static @Nonnull T readJsonFromErrorMessage(@Nonnull StoneSerializer serializer,
+ @Nonnull String message,
+ @Nullable String requestId)
throws JsonParseException {
ApiErrorResponse errorResponse = new ApiErrorResponse.Serializer(serializer).deserialize(message);
return errorResponse.getError();
}
public static abstract class ResponseHandler {
- public abstract T handle(HttpRequestor.Response response) throws DbxException;
+ public abstract @Nullable T handle(@Nonnull HttpRequestor.Response response) throws DbxException;
}
- public static T doGet(final DbxRequestConfig requestConfig,
- final String accessToken,
- final String sdkUserAgentIdentifier,
- final String host,
- final String path,
- final /*@Nullable*/String/*@Nullable*/[] params,
- final /*@Nullable*/List headers,
- final ResponseHandler handler)
+ public static @Nullable T doGet(final @Nonnull DbxRequestConfig requestConfig,
+ final @Nonnull String accessToken,
+ final @Nonnull String sdkUserAgentIdentifier,
+ final @Nonnull String host,
+ final @Nonnull String path,
+ final @Nullable String[] params,
+ final @Nullable List headers,
+ final @Nonnull ResponseHandler handler)
throws DbxException {
return runAndRetry(requestConfig.getMaxRetries(), new RequestMaker() {
@Override
- public T run() throws DbxException {
+ public @Nullable T run() throws DbxException {
HttpRequestor.Response response = startGet(requestConfig, accessToken, sdkUserAgentIdentifier, host, path, params, headers);
try {
return handler.handle(response);
} finally {
- try {
- response.getBody().close();
- } catch (IOException ex) {
- //noinspection ThrowFromFinallyBlock
- throw new NetworkIOException(ex);
- }
+ IOUtil.closeInput(response.getBody());
}
}
});
}
- public static T doPost(DbxRequestConfig requestConfig,
- String accessToken,
- String sdkUserAgentIdentifier,
- String host,
- String path,
- /*@Nullable*/String/*@Nullable*/[] params,
- /*@Nullable*/List headers,
- ResponseHandler handler)
+ public static @Nullable T doPost(@Nonnull DbxRequestConfig requestConfig,
+ @Nonnull String accessToken,
+ @Nonnull String sdkUserAgentIdentifier,
+ @Nonnull String host,
+ @Nonnull String path,
+ @Nullable String[] params,
+ @Nullable List headers,
+ @Nonnull ResponseHandler handler)
throws DbxException {
headers = copyHeaders(headers);
headers = addAuthHeader(headers, accessToken);
return doPostNoAuth(requestConfig, sdkUserAgentIdentifier, host, path, params, headers, handler);
}
- public static T doPostNoAuth(final DbxRequestConfig requestConfig,
- final String sdkUserAgentIdentifier,
- final String host,
- final String path,
- final /*@Nullable*/String/*@Nullable*/[] params,
- final /*@Nullable*/List headers,
- final ResponseHandler handler)
+ public static @Nullable T doPostNoAuth(final @Nonnull DbxRequestConfig requestConfig,
+ final @Nonnull String sdkUserAgentIdentifier,
+ final @Nonnull String host,
+ final @Nonnull String path,
+ final @Nullable String[] params,
+ final @Nullable List headers,
+ final @Nonnull ResponseHandler handler)
throws DbxException {
return runAndRetry(requestConfig.getMaxRetries(), new RequestMaker() {
@Override
- public T run() throws DbxException {
+ public @Nullable T run() throws DbxException {
HttpRequestor.Response response = startPostNoAuth(requestConfig, sdkUserAgentIdentifier, host, path, params, headers);
return finishResponse(response, handler);
}
});
}
- public static T finishResponse(HttpRequestor.Response response, ResponseHandler handler) throws DbxException {
+ public static @Nullable T finishResponse(@Nonnull HttpRequestor.Response response,
+ @Nonnull ResponseHandler handler) throws DbxException {
try {
return handler.handle(response);
} finally {
@@ -522,7 +531,8 @@ public static T finishResponse(HttpRequestor.Response response, ResponseHand
}
}
- public static String getFirstHeader(HttpRequestor.Response response, String name) throws BadResponseException {
+ public static @Nonnull String getFirstHeader(@Nonnull HttpRequestor.Response response,
+ @Nonnull String name) throws BadResponseException {
List values = response.getHeaders().get(name);
if (values == null || values.isEmpty()) {
throw new BadResponseException(getRequestId(response), "missing HTTP header \"" + name + "\"");
@@ -530,7 +540,7 @@ public static String getFirstHeader(HttpRequestor.Response response, String name
return values.get(0);
}
- public static /*@Nullable*/String getFirstHeaderMaybe(HttpRequestor.Response response, String name) {
+ public static @Nullable String getFirstHeaderMaybe(@Nonnull HttpRequestor.Response response, @Nonnull String name) {
List values = response.getHeaders().get(name);
if (values == null || values.isEmpty()) {
return null;
@@ -538,19 +548,20 @@ public static String getFirstHeader(HttpRequestor.Response response, String name
return values.get(0);
}
- public static /*@Nullable*/ String getRequestId(HttpRequestor.Response response) {
+ public static @Nullable String getRequestId(@Nonnull HttpRequestor.Response response) {
return DbxRequestUtil.getFirstHeaderMaybe(response, "X-Dropbox-Request-Id");
}
- public static /*@Nullable*/ String getContentType(HttpRequestor.Response response) {
+ public static @Nullable String getContentType(@Nonnull HttpRequestor.Response response) {
return DbxRequestUtil.getFirstHeaderMaybe(response, "Content-Type");
}
public static abstract class RequestMaker {
- public abstract T run() throws DbxException, E;
+ public abstract @Nullable T run() throws DbxException, E;
}
- public static T runAndRetry(int maxRetries, RequestMaker requestMaker)
+ public static @Nullable T runAndRetry(int maxRetries,
+ @Nonnull RequestMaker requestMaker)
throws DbxException, E {
int numRetries = 0;
while (true) {
diff --git a/core/src/main/java/com/dropbox/core/DbxSessionStore.java b/core/src/main/java/com/dropbox/core/DbxSessionStore.java
index ad2e887ad..45c660465 100644
--- a/core/src/main/java/com/dropbox/core/DbxSessionStore.java
+++ b/core/src/main/java/com/dropbox/core/DbxSessionStore.java
@@ -1,6 +1,7 @@
package com.dropbox.core;
-/*>>> import checkers.nullness.quals.Nullable; */
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
/**
* An interface that lets you save, retrieve, and clear a single value in the user's web
@@ -12,7 +13,7 @@
*
*/
public interface DbxSessionStore {
- public /*@Nullable*/String get();
- public void set(String value);
+ public @Nullable String get();
+ public void set(@Nonnull String value);
public void clear();
}
diff --git a/core/src/main/java/com/dropbox/core/DbxStandardSessionStore.java b/core/src/main/java/com/dropbox/core/DbxStandardSessionStore.java
index 8525e95c3..c2210b439 100644
--- a/core/src/main/java/com/dropbox/core/DbxStandardSessionStore.java
+++ b/core/src/main/java/com/dropbox/core/DbxStandardSessionStore.java
@@ -1,8 +1,9 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import jakarta.servlet.http.HttpSession;
-/*>>> import checkers.nullness.quals.Nullable; */
/**
* A {@link DbxSessionStore} implementation that stores the value using the standard
@@ -20,31 +21,31 @@
*
*/
public final class DbxStandardSessionStore implements DbxSessionStore {
- private final HttpSession session;
- private final String key;
+ private final @Nonnull HttpSession session;
+ private final @Nonnull String key;
- public DbxStandardSessionStore(HttpSession session, String key) {
+ public DbxStandardSessionStore(@Nonnull HttpSession session, @Nonnull String key) {
this.session = session;
this.key = key;
}
- public HttpSession getSession() {
+ public @Nonnull HttpSession getSession() {
return session;
}
- public String getKey() {
+ public @Nonnull String getKey() {
return key;
}
@Override
- public /*@Nullable*/String get() {
+ public @Nullable String get() {
Object v = session.getAttribute(key);
if (v instanceof String) return (String) v;
return null;
}
@Override
- public void set(String value) {
+ public void set(@Nonnull String value) {
session.setAttribute(key, value);
}
diff --git a/core/src/main/java/com/dropbox/core/DbxStreamReader.java b/core/src/main/java/com/dropbox/core/DbxStreamReader.java
index 7d7749d35..60c5bcb07 100644
--- a/core/src/main/java/com/dropbox/core/DbxStreamReader.java
+++ b/core/src/main/java/com/dropbox/core/DbxStreamReader.java
@@ -6,6 +6,8 @@
import java.io.InputStream;
import java.io.OutputStream;
+import javax.annotation.Nonnull;
+
/**
* A callback for streaming data from an {@link InputStream}.
*
@@ -21,7 +23,7 @@ public abstract class DbxStreamReader
* call {@link InputStream#close close()} on the stream (the stream will
* be closed automatically).
*/
- public abstract void read(NoThrowInputStream in) throws E;
+ public abstract void read(@Nonnull NoThrowInputStream in) throws E;
/**
* A {@link DbxStreamReader} that gets its source data from the given {@code OutputStream}.
@@ -29,14 +31,14 @@ public abstract class DbxStreamReader
*/
public static final class OutputStreamCopier extends DbxStreamReader
{
- private final OutputStream dest;
+ private final @Nonnull OutputStream dest;
- public OutputStreamCopier(OutputStream dest)
+ public OutputStreamCopier(@Nonnull OutputStream dest)
{
this.dest = dest;
}
- public void read(NoThrowInputStream source) throws IOException
+ public void read(@Nonnull NoThrowInputStream source) throws IOException
{
IOUtil.copyStreamToStream(source, dest);
}
@@ -44,11 +46,11 @@ public void read(NoThrowInputStream source) throws IOException
public static final class ByteArrayCopier extends DbxStreamReader
{
- private final byte[] data;
+ private final @Nonnull byte[] data;
private final int offset;
private final int length;
- public ByteArrayCopier(byte[] data, int offset, int length)
+ public ByteArrayCopier(@Nonnull byte[] data, int offset, int length)
{
if (data == null) throw new IllegalArgumentException("'data' can't be null");
if (offset < 0 || offset >= data.length) throw new IllegalArgumentException("'offset' is out of bounds");
@@ -58,13 +60,13 @@ public ByteArrayCopier(byte[] data, int offset, int length)
this.length = length;
}
- public ByteArrayCopier(byte[] data)
+ public ByteArrayCopier(@Nonnull byte[] data)
{
this(data, 0, data.length);
}
@Override
- public void read(NoThrowInputStream in)
+ public void read(@Nonnull NoThrowInputStream in)
{
in.read(this.data, this.offset, this.length);
}
diff --git a/core/src/main/java/com/dropbox/core/DbxStreamWriter.java b/core/src/main/java/com/dropbox/core/DbxStreamWriter.java
index 10df245e2..9859282ad 100644
--- a/core/src/main/java/com/dropbox/core/DbxStreamWriter.java
+++ b/core/src/main/java/com/dropbox/core/DbxStreamWriter.java
@@ -6,6 +6,8 @@
import java.io.InputStream;
import java.io.OutputStream;
+import javax.annotation.Nonnull;
+
/**
* A callback for streaming data to an {@link OutputStream}.
*
@@ -21,7 +23,7 @@ public abstract class DbxStreamWriter
* call {@link OutputStream#close close()} on the stream (the stream will
* be closed automatically).
*/
- public abstract void write(NoThrowOutputStream out) throws E;
+ public abstract void write(@Nonnull NoThrowOutputStream out) throws E;
/**
* A {@link DbxStreamWriter} that gets its source data from the given {@code InputStream}.
@@ -29,14 +31,14 @@ public abstract class DbxStreamWriter
*/
public static final class InputStreamCopier extends DbxStreamWriter
{
- private final InputStream source;
+ private final @Nonnull InputStream source;
- public InputStreamCopier(InputStream source)
+ public InputStreamCopier(@Nonnull InputStream source)
{
this.source = source;
}
- public void write(NoThrowOutputStream out) throws IOException
+ public void write(@Nonnull NoThrowOutputStream out) throws IOException
{
IOUtil.copyStreamToStream(source, out);
}
@@ -44,11 +46,11 @@ public void write(NoThrowOutputStream out) throws IOException
public static final class ByteArrayCopier extends DbxStreamWriter
{
- private final byte[] data;
+ private final @Nonnull byte[] data;
private final int offset;
private final int length;
- public ByteArrayCopier(byte[] data, int offset, int length)
+ public ByteArrayCopier(@Nonnull byte[] data, int offset, int length)
{
if (data == null) throw new IllegalArgumentException("'data' can't be null");
if (offset < 0 || offset >= data.length) throw new IllegalArgumentException("'offset' is out of bounds");
@@ -58,13 +60,13 @@ public ByteArrayCopier(byte[] data, int offset, int length)
this.length = length;
}
- public ByteArrayCopier(byte[] data)
+ public ByteArrayCopier(@Nonnull byte[] data)
{
this(data, 0, data.length);
}
@Override
- public void write(NoThrowOutputStream out)
+ public void write(@Nonnull NoThrowOutputStream out)
{
out.write(this.data, this.offset, this.length);
}
diff --git a/core/src/main/java/com/dropbox/core/DbxUploader.java b/core/src/main/java/com/dropbox/core/DbxUploader.java
index e2c1d7d61..339a36791 100644
--- a/core/src/main/java/com/dropbox/core/DbxUploader.java
+++ b/core/src/main/java/com/dropbox/core/DbxUploader.java
@@ -11,6 +11,9 @@
import com.dropbox.core.http.HttpRequestor;
import com.dropbox.core.util.IOUtil;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* Class for completing upload requests.
*
@@ -43,16 +46,19 @@
* @param exception type returned by server on request failure
*/
public abstract class DbxUploader implements Closeable {
- private final HttpRequestor.Uploader httpUploader;
- private final StoneSerializer responseSerializer;
- private final StoneSerializer errorSerializer;
+ private final @Nonnull HttpRequestor.Uploader httpUploader;
+ private final @Nonnull StoneSerializer responseSerializer;
+ private final @Nonnull StoneSerializer errorSerializer;
private boolean closed;
private boolean finished;
- private final String userId;
+ private final @Nullable String userId;
- protected DbxUploader(HttpRequestor.Uploader httpUploader, StoneSerializer responseSerializer, StoneSerializer errorSerializer, String userId) {
+ protected DbxUploader(@Nonnull HttpRequestor.Uploader httpUploader,
+ @Nonnull StoneSerializer responseSerializer,
+ @Nonnull StoneSerializer errorSerializer,
+ @Nullable String userId) {
this.httpUploader = httpUploader;
this.responseSerializer = responseSerializer;
this.errorSerializer = errorSerializer;
@@ -62,7 +68,7 @@ protected DbxUploader(HttpRequestor.Uploader httpUploader, StoneSerializer re
this.userId = userId;
}
- protected abstract X newException(DbxWrappedException error);
+ protected abstract @Nonnull X newException(@Nonnull DbxWrappedException error);
/**
* Uploads all bytes read from the given {@link InputStream} and returns the response.
@@ -92,7 +98,7 @@ protected DbxUploader(HttpRequestor.Uploader httpUploader, StoneSerializer re
* @throws IOException if an error occurs reading the input stream.
* @throws IllegalStateException if this uploader has already been closed (see {@link #close}) or finished (see {@link #finish})
*/
- public R uploadAndFinish(InputStream in) throws X, DbxException, IOException {
+ public @Nullable R uploadAndFinish(@Nonnull InputStream in) throws X, DbxException, IOException {
return uploadAndFinish(in, null);
}
@@ -111,7 +117,8 @@ public R uploadAndFinish(InputStream in) throws X, DbxException, IOException {
* @throws IOException if an error occurs reading the input stream.
* @throws IllegalStateException if this uploader has already been closed (see {@link #close}) or finished (see {@link #finish})
*/
- public R uploadAndFinish(InputStream in, IOUtil.ProgressListener progressListener) throws X, DbxException, IOException {
+ public @Nullable R uploadAndFinish(@Nonnull InputStream in,
+ @Nullable IOUtil.ProgressListener progressListener) throws X, DbxException, IOException {
try {
try {
httpUploader.setProgressListener(progressListener);
@@ -163,7 +170,7 @@ public R uploadAndFinish(InputStream in, IOUtil.ProgressListener progressListene
* @throws IOException if an error occurs reading the input stream.
* @throws IllegalStateException if this uploader has already been closed (see {@link #close}) or finished (see {@link #finish})
*/
- public R uploadAndFinish(InputStream in, long limit) throws X, DbxException, IOException {
+ public @Nullable R uploadAndFinish(@Nonnull InputStream in, long limit) throws X, DbxException, IOException {
return uploadAndFinish(IOUtil.limit(in, limit));
}
@@ -183,7 +190,9 @@ public R uploadAndFinish(InputStream in, long limit) throws X, DbxException, IOE
* @throws IOException if an error occurs reading the input stream.
* @throws IllegalStateException if this uploader has already been closed (see {@link #close}) or finished (see {@link #finish})
*/
- public R uploadAndFinish(InputStream in, long limit, IOUtil.ProgressListener progressListener) throws X, DbxException, IOException {
+ public @Nullable R uploadAndFinish(@Nonnull InputStream in,
+ long limit,
+ @Nullable IOUtil.ProgressListener progressListener) throws X, DbxException, IOException {
return uploadAndFinish(IOUtil.limit(in, limit), progressListener);
}
@@ -232,7 +241,7 @@ public void abort() {
*
* @see #uploadAndFinish(InputStream)
*/
- public OutputStream getOutputStream() {
+ public @Nonnull OutputStream getOutputStream() {
assertOpenAndUnfinished();
return this.httpUploader.getBody();
}
@@ -254,7 +263,7 @@ public OutputStream getOutputStream() {
*
* @see #uploadAndFinish(InputStream)
*/
- public OutputStream getOutputStream(IOUtil.ProgressListener progressListener) {
+ public @Nonnull OutputStream getOutputStream(@Nullable IOUtil.ProgressListener progressListener) {
this.httpUploader.setProgressListener(progressListener);
return getOutputStream();
}
@@ -271,7 +280,7 @@ public OutputStream getOutputStream(IOUtil.ProgressListener progressListener) {
* @throws DbxException if an error occurs sending the upload or reading the response
* @throws IllegalStateException if this uploader has already been closed (see {@link #close}) or finished (see {@link #finish})
*/
- public R finish() throws X, DbxException {
+ public @Nullable R finish() throws X, DbxException {
assertOpenAndUnfinished();
HttpRequestor.Response response = null;
diff --git a/core/src/main/java/com/dropbox/core/DbxWebAuth.java b/core/src/main/java/com/dropbox/core/DbxWebAuth.java
index 4baef1f07..327f9aaec 100644
--- a/core/src/main/java/com/dropbox/core/DbxWebAuth.java
+++ b/core/src/main/java/com/dropbox/core/DbxWebAuth.java
@@ -1,5 +1,7 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import static com.dropbox.core.util.StringUtil.jq;
import java.nio.charset.Charset;
@@ -14,7 +16,6 @@
import com.dropbox.core.util.StringUtil;
import com.dropbox.core.v2.DbxRawClientV2;
-/*>>> import checkers.nullness.quals.Nullable; */
/**
* Does the OAuth 2 "authorization code" flow. (This SDK does not support the "token" flow.)
@@ -141,13 +142,13 @@ public class DbxWebAuth {
private static final int CSRF_STRING_SIZE = StringUtil.urlSafeBase64Encode(new byte[CSRF_BYTES_SIZE]).length();
/** Role representing the team account associated with a user. Used by {@link Request.Builder#withRequireRole}. */
- public static final String ROLE_WORK = "work";
+ public static final @Nonnull String ROLE_WORK = "work";
/** Role representing the personal account associated with a user. Used by {@link Request.Builder#withRequireRole}. */
- public static final String ROLE_PERSONAL = "personal";
+ public static final @Nonnull String ROLE_PERSONAL = "personal";
- final DbxRequestConfig requestConfig;
- final DbxAppInfo appInfo;
- final Request deprecatedRequest;
+ final @Nonnull DbxRequestConfig requestConfig;
+ final @Nonnull DbxAppInfo appInfo;
+ final @Nullable Request deprecatedRequest;
/**
* Creates a new instance that will perform the OAuth2 authorization flow using a redirect URI.
@@ -162,7 +163,10 @@ public class DbxWebAuth {
* instead
*/
@Deprecated
- public DbxWebAuth(DbxRequestConfig requestConfig, DbxAppInfo appInfo, String redirectUri, DbxSessionStore sessionStore) {
+ public DbxWebAuth(@Nonnull DbxRequestConfig requestConfig,
+ @Nonnull DbxAppInfo appInfo,
+ @Nonnull String redirectUri,
+ @Nonnull DbxSessionStore sessionStore) {
if (requestConfig == null) throw new NullPointerException("requestConfig");
if (appInfo == null) throw new NullPointerException("appInfo");
@@ -182,7 +186,7 @@ public DbxWebAuth(DbxRequestConfig requestConfig, DbxAppInfo appInfo, String red
* @param appInfo Your application's Dropbox API information (the app key and secret), never
* {@code null}.
*/
- public DbxWebAuth(DbxRequestConfig requestConfig, DbxAppInfo appInfo) {
+ public DbxWebAuth(@Nonnull DbxRequestConfig requestConfig, @Nonnull DbxAppInfo appInfo) {
if (requestConfig == null) throw new NullPointerException("requestConfig");
if (appInfo == null) throw new NullPointerException("appInfo");
@@ -214,7 +218,7 @@ public DbxWebAuth(DbxRequestConfig requestConfig, DbxAppInfo appInfo) {
* instead.
*/
@Deprecated
- public String start(/*@Nullable*/String urlState) {
+ public @Nonnull String start(@Nullable String urlState) {
if (deprecatedRequest == null) {
throw new IllegalStateException("Must use DbxWebAuth.authorize instead.");
}
@@ -248,7 +252,7 @@ public String start(/*@Nullable*/String urlState) {
* constructor, or if this (@link DbxWebAuth} instance was created with {@link DbxAppInfo}
* without app secret.
*/
- public String authorize(Request request) {
+ public @Nonnull String authorize(@Nonnull Request request) {
if (deprecatedRequest != null) {
throw new IllegalStateException("Must create this instance using DbxWebAuth(DbxRequestConfig,DbxAppInfo) to call this method.");
}
@@ -260,11 +264,12 @@ public String authorize(Request request) {
return authorizeImpl(request);
}
- private String authorizeImpl(Request request) {
+ private @Nonnull String authorizeImpl(@Nonnull Request request) {
return authorizeImpl(request, null);
}
- String authorizeImpl(Request request, Map pkceParams) {
+ @Nonnull
+ String authorizeImpl(@Nonnull Request request, @Nullable Map pkceParams) {
Map params = new HashMap();
params.put("client_id", appInfo.getKey());
@@ -319,7 +324,7 @@ String authorizeImpl(Request request, Map pkceParams) {
*
* @throws DbxException if an error occurs communicating with Dropbox.
*/
- public DbxAuthFinish finishFromCode(String code) throws DbxException {
+ public @Nonnull DbxAuthFinish finishFromCode(@Nonnull String code) throws DbxException {
return finish(code);
}
@@ -333,7 +338,7 @@ public DbxAuthFinish finishFromCode(String code) throws DbxException {
*
* @throws DbxException if an error occurs communicating with Dropbox.
*/
- public DbxAuthFinish finishFromCode(String code, String redirectUri) throws DbxException {
+ public @Nonnull DbxAuthFinish finishFromCode(@Nonnull String code, @Nonnull String redirectUri) throws DbxException {
return finish(code, redirectUri, null);
}
@@ -359,17 +364,19 @@ public DbxAuthFinish finishFromCode(String code, String redirectUri) throws DbxE
* set.
* @throws DbxException If an error occurs communicating with Dropbox.
*/
- public DbxAuthFinish finishFromRedirect(String redirectUri,
- DbxSessionStore sessionStore,
- Map params)
+ public @Nonnull DbxAuthFinish finishFromRedirect(@Nonnull String redirectUri,
+ @Nonnull DbxSessionStore sessionStore,
+ @Nonnull Map params)
throws DbxException, BadRequestException, BadStateException, CsrfException, NotApprovedException, ProviderException {
- String strippedState = validateRedirectUri(redirectUri, sessionStore, params);
+ @Nullable String strippedState = validateRedirectUri(redirectUri, sessionStore, params);
String code = getParam(params, "code");
return finish(code, redirectUri, strippedState);
}
- static String validateRedirectUri(String redirectUri, DbxSessionStore sessionStore, Map params)
+ static @Nullable String validateRedirectUri(@Nonnull String redirectUri,
+ @Nonnull DbxSessionStore sessionStore,
+ @Nonnull Map params)
throws BadRequestException, BadStateException, CsrfException, NotApprovedException, ProviderException
{
if (redirectUri == null) throw new NullPointerException("redirectUri");
@@ -416,11 +423,12 @@ static String validateRedirectUri(String redirectUri, DbxSessionStore sessionSto
return state;
}
- private DbxAuthFinish finish(String code) throws DbxException {
+ private @Nonnull DbxAuthFinish finish(@Nonnull String code) throws DbxException {
return finish(code, null, null);
}
- DbxAuthFinish finish(String code, String redirectUri, final String state) throws
+ @Nonnull
+ DbxAuthFinish finish(@Nonnull String code, @Nullable String redirectUri, final @Nullable String state) throws
DbxException {
if (code == null) throw new NullPointerException("code");
if (!appInfo.hasSecret()) {
@@ -437,7 +445,11 @@ DbxAuthFinish finish(String code, String redirectUri, final String state) throws
}
List headers = new ArrayList();
- DbxRequestUtil.addBasicAuthHeader(headers, appInfo.getKey(), appInfo.getSecret());
+ String appSecret = appInfo.getSecret();
+ if (appSecret == null) {
+ throw new IllegalStateException("App secret is required for non-PKCE OAuth.");
+ }
+ DbxRequestUtil.addBasicAuthHeader(headers, appInfo.getKey(), appSecret);
return DbxRequestUtil.doPostNoAuth(
requestConfig,
@@ -448,7 +460,7 @@ DbxAuthFinish finish(String code, String redirectUri, final String state) throws
headers,
new DbxRequestUtil.ResponseHandler() {
@Override
- public DbxAuthFinish handle(HttpRequestor.Response response) throws DbxException {
+ public @Nonnull DbxAuthFinish handle(@Nonnull HttpRequestor.Response response) throws DbxException {
if (response.getStatusCode() != 200) {
throw DbxRequestUtil.unexpectedStatus(response);
}
@@ -481,7 +493,7 @@ public DbxAuthFinish handle(HttpRequestor.Response response) throws DbxException
* @deprecated use {@link #finishFromRedirect finishFromRedirect(..)} instead.
*/
@Deprecated
- public DbxAuthFinish finish(Map queryParams)
+ public @Nonnull DbxAuthFinish finish(@Nonnull Map queryParams)
throws DbxException, BadRequestException, BadStateException, CsrfException, NotApprovedException, ProviderException {
if (deprecatedRequest == null) {
throw new IllegalStateException("Must use DbxWebAuth.finishFromRedirect(..) instead.");
@@ -493,7 +505,7 @@ public DbxAuthFinish finish(Map queryParams)
);
}
- private static String appendCsrfToken(Request request) {
+ private static @Nonnull String appendCsrfToken(@Nonnull Request request) {
// add a CSRF nonce for security
byte[] csrf = new byte[CSRF_BYTES_SIZE];
RAND.nextBytes(csrf);
@@ -518,7 +530,7 @@ private static String appendCsrfToken(Request request) {
}
}
- private static String verifyAndStripCsrfToken(String state, DbxSessionStore sessionStore)
+ private static @Nullable String verifyAndStripCsrfToken(@Nonnull String state, @Nonnull DbxSessionStore sessionStore)
throws CsrfException, BadStateException {
String expected = sessionStore.get();
if (expected == null) {
@@ -544,7 +556,7 @@ private static String verifyAndStripCsrfToken(String state, DbxSessionStore sess
return stripped.isEmpty() ? null : stripped;
}
- static /*@Nullable*/String getParam(Map params, String name) throws BadRequestException {
+ static @Nullable String getParam(@Nonnull Map params, @Nonnull String name) throws BadRequestException {
String[] v = params.get(name);
if (v == null) {
@@ -564,7 +576,7 @@ private static String verifyAndStripCsrfToken(String state, DbxSessionStore sess
*/
public static abstract class Exception extends java.lang.Exception {
private static final long serialVersionUID = 0L;
- public Exception(String message) { super(message); }
+ public Exception(@Nonnull String message) { super(message); }
}
/**
@@ -580,7 +592,7 @@ public static abstract class Exception extends java.lang.Exception {
*/
public static final class BadRequestException extends Exception {
private static final long serialVersionUID = 0L;
- public BadRequestException(String message) { super(message); }
+ public BadRequestException(@Nonnull String message) { super(message); }
}
/**
@@ -598,7 +610,7 @@ public static final class BadRequestException extends Exception {
*/
public static final class BadStateException extends Exception {
private static final long serialVersionUID = 0L;
- public BadStateException(String message) { super(message); }
+ public BadStateException(@Nonnull String message) { super(message); }
}
/**
@@ -615,7 +627,7 @@ public static final class BadStateException extends Exception {
*/
public static final class CsrfException extends Exception {
private static final long serialVersionUID = 0L;
- public CsrfException(String message) { super(message); }
+ public CsrfException(@Nonnull String message) { super(message); }
}
/**
@@ -628,7 +640,7 @@ public static final class CsrfException extends Exception {
*/
public static final class NotApprovedException extends Exception {
private static final long serialVersionUID = 0L;
- public NotApprovedException(String message) { super(message); }
+ public NotApprovedException(@Nonnull String message) { super(message); }
}
/**
@@ -640,7 +652,7 @@ public static final class NotApprovedException extends Exception {
*/
public static final class ProviderException extends Exception {
private static final long serialVersionUID = 0L;
- public ProviderException(String message) { super(message); }
+ public ProviderException(@Nonnull String message) { super(message); }
}
/**
@@ -648,7 +660,7 @@ public static final class ProviderException extends Exception {
*
* @return new request builder with default values
*/
- public static Request.Builder newRequestBuilder() {
+ public static @Nonnull Request.Builder newRequestBuilder() {
return Request.newBuilder();
}
@@ -661,26 +673,26 @@ public static final class Request {
private static final Charset UTF8 = Charset.forName("UTF-8");
private static final int MAX_STATE_SIZE = 500;
- private final String redirectUri;
- private final String state;
- private final String requireRole;
- private final Boolean forceReapprove;
- private final Boolean disableSignup;
- private final DbxSessionStore sessionStore;
- private final TokenAccessType tokenAccessType;
- private final String scope;
- private final IncludeGrantedScopes includeGrantedScopes;
-
-
- private Request(String redirectUri,
- String state,
- String requireRole,
- Boolean forceReapprove,
- Boolean disableSignup,
- DbxSessionStore sessionStore,
- TokenAccessType tokenAccessType,
- String scope,
- IncludeGrantedScopes includeGrantedScopes) {
+ private final @Nullable String redirectUri;
+ private final @Nullable String state;
+ private final @Nullable String requireRole;
+ private final @Nullable Boolean forceReapprove;
+ private final @Nullable Boolean disableSignup;
+ private final @Nullable DbxSessionStore sessionStore;
+ private final @Nullable TokenAccessType tokenAccessType;
+ private final @Nullable String scope;
+ private final @Nullable IncludeGrantedScopes includeGrantedScopes;
+
+
+ private Request(@Nullable String redirectUri,
+ @Nullable String state,
+ @Nullable String requireRole,
+ @Nullable Boolean forceReapprove,
+ @Nullable Boolean disableSignup,
+ @Nullable DbxSessionStore sessionStore,
+ @Nullable TokenAccessType tokenAccessType,
+ @Nullable String scope,
+ @Nullable IncludeGrantedScopes includeGrantedScopes) {
this.redirectUri = redirectUri;
this.state = state;
this.requireRole = requireRole;
@@ -697,7 +709,7 @@ private Request(String redirectUri,
*
* @return copy of this request
*/
- public Builder copy() {
+ public @Nonnull Builder copy() {
return new Builder(
redirectUri,
state,
@@ -716,7 +728,7 @@ public Builder copy() {
*
* @return new request builder with default values
*/
- public static Builder newBuilder() {
+ public static @Nonnull Builder newBuilder() {
return new Builder();
}
@@ -724,29 +736,29 @@ public static Builder newBuilder() {
* Builder for OAuth2 requests. Use this builder to configure the OAuth authorization flow.
*/
public static final class Builder {
- private String redirectUri;
- private String state;
- private String requireRole;
- private Boolean forceReapprove;
- private Boolean disableSignup;
- private DbxSessionStore sessionStore;
- private TokenAccessType tokenAccessType;
- private String scope;
- private IncludeGrantedScopes includeGrantedScopes;
+ private @Nullable String redirectUri;
+ private @Nullable String state;
+ private @Nullable String requireRole;
+ private @Nullable Boolean forceReapprove;
+ private @Nullable Boolean disableSignup;
+ private @Nullable DbxSessionStore sessionStore;
+ private @Nullable TokenAccessType tokenAccessType;
+ private @Nullable String scope;
+ private @Nullable IncludeGrantedScopes includeGrantedScopes;
private Builder() {
this(null, null, null, null, null, null, null, null, null);
}
- private Builder(String redirectUri,
- String state,
- String requireRole,
- Boolean forceReapprove,
- Boolean disableSignup,
- DbxSessionStore sessionStore,
- TokenAccessType tokenAccessType,
- String scope,
- IncludeGrantedScopes includeGrantedScopes) {
+ private Builder(@Nullable String redirectUri,
+ @Nullable String state,
+ @Nullable String requireRole,
+ @Nullable Boolean forceReapprove,
+ @Nullable Boolean disableSignup,
+ @Nullable DbxSessionStore sessionStore,
+ @Nullable TokenAccessType tokenAccessType,
+ @Nullable String scope,
+ @Nullable IncludeGrantedScopes includeGrantedScopes) {
this.redirectUri = redirectUri;
this.state = state;
this.requireRole = requireRole;
@@ -768,7 +780,7 @@ private Builder(String redirectUri,
*
* @return this builder
*/
- public Builder withNoRedirect() {
+ public @Nonnull Builder withNoRedirect() {
this.redirectUri = null;
this.sessionStore = null;
return this;
@@ -797,7 +809,7 @@ public Builder withNoRedirect() {
*
* @throws NullPointerException if either redirectUri or sessionStore is {@code null}
*/
- public Builder withRedirectUri(String redirectUri, DbxSessionStore sessionStore) {
+ public @Nonnull Builder withRedirectUri(@Nonnull String redirectUri, @Nonnull DbxSessionStore sessionStore) {
if (redirectUri == null) throw new NullPointerException("redirectUri");
if (sessionStore == null) throw new NullPointerException("sessionStore");
@@ -824,7 +836,7 @@ public Builder withRedirectUri(String redirectUri, DbxSessionStore sessionStore)
*
* @throws IllegalArgumentException if state is greater than 476 bytes
*/
- public Builder withState(String state) {
+ public @Nonnull Builder withState(@Nullable String state) {
if (state != null && (state.getBytes(UTF8).length + CSRF_STRING_SIZE) > MAX_STATE_SIZE) {
throw new IllegalArgumentException("UTF-8 encoded state cannot be greater than " + (MAX_STATE_SIZE - CSRF_STRING_SIZE) + " bytes.");
}
@@ -846,7 +858,7 @@ public Builder withState(String state) {
* @see DbxWebAuth#ROLE_WORK
* @see DbxWebAuth#ROLE_PERSONAL
*/
- public Builder withRequireRole(String requireRole) {
+ public @Nonnull Builder withRequireRole(@Nullable String requireRole) {
this.requireRole = requireRole;
return this;
}
@@ -864,7 +876,7 @@ public Builder withRequireRole(String requireRole) {
* @param forceReapprove whether to force a user to re-approve this app, or {@code null}
* for default behavior
*/
- public Builder withForceReapprove(Boolean forceReapprove) {
+ public @Nonnull Builder withForceReapprove(@Nullable Boolean forceReapprove) {
this.forceReapprove = forceReapprove;
return this;
}
@@ -882,7 +894,7 @@ public Builder withForceReapprove(Boolean forceReapprove) {
*
* @return this builder
*/
- public Builder withDisableSignup(Boolean disableSignup) {
+ public @Nonnull Builder withDisableSignup(@Nullable Boolean disableSignup) {
this.disableSignup = disableSignup;
return this;
}
@@ -902,7 +914,7 @@ public Builder withDisableSignup(Boolean disableSignup) {
*
* @return this builder
*/
- public Builder withTokenAccessType(TokenAccessType tokenAccessType) {
+ public @Nonnull Builder withTokenAccessType(@Nullable TokenAccessType tokenAccessType) {
this.tokenAccessType = tokenAccessType;
return this;
}
@@ -914,7 +926,7 @@ public Builder withTokenAccessType(TokenAccessType tokenAccessType) {
* API endpoints. To call one API endpoint you have to obtains the scope first otherwise you
* will get HTTP 401. Example: "account_info.read files.content.read"
*/
- public Builder withScope(Collection scope) {
+ public @Nonnull Builder withScope(@Nullable Collection scope) {
if (scope != null) {
this.scope = StringUtil.join(scope, " ");
}
@@ -931,7 +943,7 @@ public Builder withScope(Collection scope) {
* scopes user previously granted your app together with
* the new scopes.
*/
- public Builder withIncludeGrantedScopes(IncludeGrantedScopes includeGrantedScopes) {
+ public @Nonnull Builder withIncludeGrantedScopes(@Nullable IncludeGrantedScopes includeGrantedScopes) {
this.includeGrantedScopes = includeGrantedScopes;
return this;
}
@@ -945,7 +957,7 @@ public Builder withIncludeGrantedScopes(IncludeGrantedScopes includeGrantedScope
* @throws IllegalStateException if {@link #withState} was called with a non-{@code
* null} value, but no redirect URI was specified.
*/
- public Request build() {
+ public @Nonnull Request build() {
if (redirectUri == null && state != null) {
throw new IllegalStateException("Cannot specify a state without a redirect URI.");
}
diff --git a/core/src/main/java/com/dropbox/core/DbxWebAuthNoRedirect.java b/core/src/main/java/com/dropbox/core/DbxWebAuthNoRedirect.java
index ad208e56e..6b69e0449 100644
--- a/core/src/main/java/com/dropbox/core/DbxWebAuthNoRedirect.java
+++ b/core/src/main/java/com/dropbox/core/DbxWebAuthNoRedirect.java
@@ -2,6 +2,8 @@
import com.dropbox.core.v2.DbxClientV2;
+import javax.annotation.Nonnull;
+
/**
* Does the OAuth web-based authorization flow for apps that can't provide a redirect URI (such as
* the command-line example apps that come with this SDK). If you're a normal website, use the
@@ -47,13 +49,13 @@
*/
@Deprecated
public class DbxWebAuthNoRedirect {
- private final DbxWebAuth auth;
+ private final @Nonnull DbxWebAuth auth;
/**
* @param appInfo
* Your application's Dropbox API information (the app key and secret).
*/
- public DbxWebAuthNoRedirect(DbxRequestConfig requestConfig, DbxAppInfo appInfo) {
+ public DbxWebAuthNoRedirect(@Nonnull DbxRequestConfig requestConfig, @Nonnull DbxAppInfo appInfo) {
this.auth = new DbxWebAuth(requestConfig, appInfo);
}
@@ -67,7 +69,7 @@ public DbxWebAuthNoRedirect(DbxRequestConfig requestConfig, DbxAppInfo appInfo)
* access token.
*
*/
- public String start() {
+ public @Nonnull String start() {
DbxWebAuth.Request request = DbxWebAuth.newRequestBuilder()
.withNoRedirect()
.build();
@@ -82,7 +84,7 @@ public String start() {
* The authorization code shown to the user when they clicked "Allow" on the authorization
* page on the Dropbox website.
*/
- public DbxAuthFinish finish(String code) throws DbxException {
+ public @Nonnull DbxAuthFinish finish(@Nonnull String code) throws DbxException {
return auth.finishFromCode(code);
}
}
diff --git a/core/src/main/java/com/dropbox/core/DbxWrappedException.java b/core/src/main/java/com/dropbox/core/DbxWrappedException.java
index d7ea999a7..569545b40 100644
--- a/core/src/main/java/com/dropbox/core/DbxWrappedException.java
+++ b/core/src/main/java/com/dropbox/core/DbxWrappedException.java
@@ -11,35 +11,42 @@
import com.dropbox.core.v2.callbacks.DbxGlobalCallbackFactory;
import com.dropbox.core.v2.callbacks.DbxRouteErrorCallback;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* For internal use only.
*/
public final class DbxWrappedException extends Exception {
private static final long serialVersionUID = 0L;
- private final Object errValue; // Really an ErrT instance, but Throwable does not allow generic subclasses.
- private final String requestId;
- private final LocalizedText userMessage;
+ private final @Nonnull Object errValue; // Really an ErrT instance, but Throwable does not allow generic subclasses.
+ private final @Nullable String requestId;
+ private final @Nullable LocalizedText userMessage;
- public DbxWrappedException(Object errValue, String requestId, LocalizedText userMessage) {
+ public DbxWrappedException(@Nonnull Object errValue,
+ @Nullable String requestId,
+ @Nullable LocalizedText userMessage) {
this.errValue = errValue;
this.requestId = requestId;
this.userMessage = userMessage;
}
- public Object getErrorValue() {
+ public @Nonnull Object getErrorValue() {
return errValue;
}
- public String getRequestId() {
+ public @Nullable String getRequestId() {
return requestId;
}
- public LocalizedText getUserMessage() {
+ public @Nullable LocalizedText getUserMessage() {
return userMessage;
}
- public static DbxWrappedException fromResponse(StoneSerializer errSerializer, HttpRequestor.Response response, String userId)
+ public static @Nonnull DbxWrappedException fromResponse(@Nonnull StoneSerializer errSerializer,
+ @Nonnull HttpRequestor.Response response,
+ @Nullable String userId)
throws IOException, JsonParseException {
String requestId = DbxRequestUtil.getRequestId(response);
@@ -55,7 +62,9 @@ public static DbxWrappedException fromResponse(StoneSerializer errSeriali
return new DbxWrappedException(routeError, requestId, apiResponse.getUserMessage());
}
- public static void executeOtherBlocks(DbxGlobalCallbackFactory factory, String userId, Object routeError) {
+ public static void executeOtherBlocks(@Nullable DbxGlobalCallbackFactory factory,
+ @Nullable String userId,
+ @Nullable Object routeError) {
try {
// Recursively looks at union errors and the union's current tag type. If there is a handler
// for the current tag type, it is executed.
@@ -75,7 +84,9 @@ public static void executeOtherBlocks(DbxGlobalCallbackFactory factory, String u
}
}
- public static void executeBlockForObject(DbxGlobalCallbackFactory factory, String userId, T routeError) {
+ public static void executeBlockForObject(@Nullable DbxGlobalCallbackFactory factory,
+ @Nullable String userId,
+ @Nullable T routeError) {
if (factory != null) {
DbxRouteErrorCallback callback = factory.createRouteErrorCallback(userId, routeError);
if (callback != null) {
diff --git a/core/src/main/java/com/dropbox/core/IncludeGrantedScopes.java b/core/src/main/java/com/dropbox/core/IncludeGrantedScopes.java
index 8ccc60f6f..3fb82c721 100644
--- a/core/src/main/java/com/dropbox/core/IncludeGrantedScopes.java
+++ b/core/src/main/java/com/dropbox/core/IncludeGrantedScopes.java
@@ -1,5 +1,7 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+
/**
* If this field is present, Dropbox server will return a token with all scopes user previously
* granted your app.
@@ -17,7 +19,7 @@ public enum IncludeGrantedScopes {
TEAM;
@Override
- public String toString() {
+ public @Nonnull String toString() {
return this.name().toLowerCase();
}
}
diff --git a/core/src/main/java/com/dropbox/core/InvalidAccessTokenException.java b/core/src/main/java/com/dropbox/core/InvalidAccessTokenException.java
index 015efa101..3c52502f2 100644
--- a/core/src/main/java/com/dropbox/core/InvalidAccessTokenException.java
+++ b/core/src/main/java/com/dropbox/core/InvalidAccessTokenException.java
@@ -2,6 +2,9 @@
import com.dropbox.core.v2.auth.AuthError;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* Gets thrown when the access token you're using to make API calls is invalid.
*
@@ -15,14 +18,16 @@
*/
public class InvalidAccessTokenException extends DbxException {
private static final long serialVersionUID = 0;
- private AuthError authError;
+ private @Nonnull AuthError authError;
- public InvalidAccessTokenException(String requestId, String message, AuthError authError) {
+ public InvalidAccessTokenException(@Nullable String requestId,
+ @Nullable String message,
+ @Nonnull AuthError authError) {
super(requestId, message);
this.authError = authError;
}
- public AuthError getAuthError() {
+ public @Nonnull AuthError getAuthError() {
return this.authError;
}
}
diff --git a/core/src/main/java/com/dropbox/core/LocalizedText.java b/core/src/main/java/com/dropbox/core/LocalizedText.java
index 63de27e9b..8d1ffd9f6 100644
--- a/core/src/main/java/com/dropbox/core/LocalizedText.java
+++ b/core/src/main/java/com/dropbox/core/LocalizedText.java
@@ -11,12 +11,14 @@
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonToken;
+import javax.annotation.Nonnull;
+
/**
* Human-readable text localized to a specific locale.
*/
public final class LocalizedText {
- private final String text;
- private final String locale;
+ private final @Nonnull String text;
+ private final @Nonnull String locale;
/**
* Create a {@link LocalizedText} object that contains the given {@code text} already localized
@@ -25,7 +27,7 @@ public final class LocalizedText {
* @param text Localized, human-readable text. Must not be {@code null}
* @param locale IETF BCP 47 language tag of text locale. Must not be {@code null}
*/
- public LocalizedText(String text, String locale) {
+ public LocalizedText(@Nonnull String text, @Nonnull String locale) {
if (text == null) {
throw new NullPointerException("text");
}
@@ -42,7 +44,7 @@ public LocalizedText(String text, String locale) {
*
* @return localized, human-readable text, never {@code null}
*/
- public String getText() {
+ public @Nonnull String getText() {
return text;
}
@@ -51,12 +53,12 @@ public String getText() {
*
* @return locale of text in IETF BCP 47 language tag format, never {@code null}
*/
- public String getLocale() {
+ public @Nonnull String getLocale() {
return locale;
}
@Override
- public String toString() {
+ public @Nonnull String toString() {
return text;
}
@@ -65,12 +67,12 @@ public String toString() {
*/
static final StoneSerializer STONE_SERIALIZER = new StoneSerializer() {
@Override
- public void serialize(LocalizedText value, JsonGenerator g) throws IOException, JsonGenerationException {
+ public void serialize(@Nonnull LocalizedText value, @Nonnull JsonGenerator g) throws IOException, JsonGenerationException {
throw new UnsupportedOperationException("Error wrapper serialization not supported.");
}
@Override
- public LocalizedText deserialize(JsonParser p) throws IOException, JsonParseException {
+ public @Nonnull LocalizedText deserialize(@Nonnull JsonParser p) throws IOException, JsonParseException {
String text = null;
String locale = null;
diff --git a/core/src/main/java/com/dropbox/core/NetworkIOException.java b/core/src/main/java/com/dropbox/core/NetworkIOException.java
index 9b54b120d..98aab8c98 100644
--- a/core/src/main/java/com/dropbox/core/NetworkIOException.java
+++ b/core/src/main/java/com/dropbox/core/NetworkIOException.java
@@ -3,6 +3,8 @@
import javax.net.ssl.SSLHandshakeException;
import java.io.IOException;
import java.security.cert.CertPathValidatorException;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
/**
* This gets thrown when there's an {@link IOException} when reading or writing to the
@@ -15,12 +17,15 @@
public class NetworkIOException extends DbxException {
private static final long serialVersionUID = 0L;
- public NetworkIOException(IOException cause) {
+ public NetworkIOException(@Nonnull IOException cause) {
super(computeMessage(cause), cause);
}
- private static String computeMessage(IOException ex) {
- String message = ex.getMessage();
+ private static @Nonnull String computeMessage(@Nonnull IOException ex) {
+ @Nullable String message = ex.getMessage();
+ if (message == null) {
+ message = ex.toString();
+ }
// For CertPathValidationErrors, the CertPath is in the exception object but not
// in the exception message. Pull it out into the message, because it would be
@@ -37,9 +42,8 @@ private static String computeMessage(IOException ex) {
}
@Override
- public IOException getCause() {
+ public @Nonnull IOException getCause() {
// guaranteed to be an IOException
return (IOException) super.getCause();
}
}
-
diff --git a/core/src/main/java/com/dropbox/core/NoThrowInputStream.java b/core/src/main/java/com/dropbox/core/NoThrowInputStream.java
index 731cd9071..238b2117f 100644
--- a/core/src/main/java/com/dropbox/core/NoThrowInputStream.java
+++ b/core/src/main/java/com/dropbox/core/NoThrowInputStream.java
@@ -4,6 +4,8 @@
import java.io.InputStream;
import java.io.OutputStream;
+import javax.annotation.Nonnull;
+
/**
* Wraps an existing input stream, converting all the underlying stream's {@code IOException}s
* to our own {@link HiddenException}, which is a subclass of {@code RuntimeException}. This
@@ -21,10 +23,10 @@
*
*/
public final class NoThrowInputStream extends InputStream {
- private final InputStream underlying;
+ private final @Nonnull InputStream underlying;
private long bytesRead = 0;
- public NoThrowInputStream(InputStream underlying) {
+ public NoThrowInputStream(@Nonnull InputStream underlying) {
this.underlying = underlying;
}
@@ -44,7 +46,7 @@ public int read() {
}
@Override
- public int read(byte[] b, int off, int len) {
+ public int read(@Nonnull byte[] b, int off, int len) {
try {
int bytesReadNow = underlying.read(b, off, len);
this.bytesRead += bytesReadNow;
@@ -56,7 +58,7 @@ public int read(byte[] b, int off, int len) {
}
@Override
- public int read(byte[] b) {
+ public int read(@Nonnull byte[] b) {
try {
int bytesReadNow = underlying.read(b);
this.bytesRead += bytesReadNow;
@@ -69,12 +71,12 @@ public int read(byte[] b) {
public static final class HiddenException extends RuntimeException {
private static final long serialVersionUID = 0L;
- public HiddenException(IOException underlying) {
+ public HiddenException(@Nonnull IOException underlying) {
super(underlying);
}
@Override
- public IOException getCause() {
+ public @Nonnull IOException getCause() {
return (IOException) super.getCause();
}
}
diff --git a/core/src/main/java/com/dropbox/core/NoThrowOutputStream.java b/core/src/main/java/com/dropbox/core/NoThrowOutputStream.java
index 6bf2175a2..269da3d2a 100644
--- a/core/src/main/java/com/dropbox/core/NoThrowOutputStream.java
+++ b/core/src/main/java/com/dropbox/core/NoThrowOutputStream.java
@@ -3,6 +3,8 @@
import java.io.IOException;
import java.io.OutputStream;
+import javax.annotation.Nonnull;
+
/**
* Wraps an existing output stream, converting all the underlying stream's {@code IOException}s
* to our own {@link HiddenException}, which is a subclass of {@code RuntimeException}. This
@@ -21,10 +23,10 @@
*/
public final class NoThrowOutputStream extends OutputStream
{
- private final OutputStream underlying;
+ private final @Nonnull OutputStream underlying;
private long bytesWritten = 0;
- public NoThrowOutputStream(OutputStream underlying)
+ public NoThrowOutputStream(@Nonnull OutputStream underlying)
{
this.underlying = underlying;
}
@@ -47,7 +49,7 @@ public void flush()
}
@Override
- public void write(byte[] b, int off, int len)
+ public void write(@Nonnull byte[] b, int off, int len)
{
try {
bytesWritten += len;
@@ -59,7 +61,7 @@ public void write(byte[] b, int off, int len)
}
@Override
- public void write(byte[] b)
+ public void write(@Nonnull byte[] b)
{
try {
bytesWritten += b.length;
@@ -84,16 +86,16 @@ public void write(int b)
public static final class HiddenException extends RuntimeException
{
- public final NoThrowOutputStream owner;
+ public final @Nonnull NoThrowOutputStream owner;
- public HiddenException(NoThrowOutputStream owner, IOException underlying)
+ public HiddenException(@Nonnull NoThrowOutputStream owner, @Nonnull IOException underlying)
{
super(underlying);
this.owner = owner;
}
@Override
- public IOException getCause()
+ public @Nonnull IOException getCause()
{
return (IOException) super.getCause();
}
diff --git a/core/src/main/java/com/dropbox/core/PathRootErrorException.java b/core/src/main/java/com/dropbox/core/PathRootErrorException.java
index 8a4acde97..b25aadf9b 100644
--- a/core/src/main/java/com/dropbox/core/PathRootErrorException.java
+++ b/core/src/main/java/com/dropbox/core/PathRootErrorException.java
@@ -2,19 +2,24 @@
import com.dropbox.core.v2.common.PathRootError;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* Gets thrown when an invalid path rood is supplied.
*/
public class PathRootErrorException extends DbxException {
private static final long serialVersionUID = 0;
- private final PathRootError pathRootError;
+ private final @Nonnull PathRootError pathRootError;
- public PathRootError getPathRootError() {
+ public @Nonnull PathRootError getPathRootError() {
return pathRootError;
}
- public PathRootErrorException(String requestId, String message, PathRootError pathRootError) {
+ public PathRootErrorException(@Nullable String requestId,
+ @Nullable String message,
+ @Nonnull PathRootError pathRootError) {
super(requestId, message);
this.pathRootError = pathRootError;
}
diff --git a/core/src/main/java/com/dropbox/core/ProtocolException.java b/core/src/main/java/com/dropbox/core/ProtocolException.java
index 54775f9bd..d0bf7756e 100644
--- a/core/src/main/java/com/dropbox/core/ProtocolException.java
+++ b/core/src/main/java/com/dropbox/core/ProtocolException.java
@@ -1,5 +1,8 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* Something unexpected happened with either the request or the response.
* This can happen if there's a bug in the client code (including this
@@ -15,12 +18,11 @@
public abstract class ProtocolException extends DbxException {
private static final long serialVersionUID = 0;
- public ProtocolException(String requestId, String message) {
+ public ProtocolException(@Nullable String requestId, @Nullable String message) {
super(requestId, message);
}
- public ProtocolException(String requestId, String message, Throwable cause) {
+ public ProtocolException(@Nullable String requestId, @Nullable String message, @Nonnull Throwable cause) {
super(requestId, message, cause);
}
}
-
diff --git a/core/src/main/java/com/dropbox/core/RateLimitException.java b/core/src/main/java/com/dropbox/core/RateLimitException.java
index 0c35c50f3..12234b885 100644
--- a/core/src/main/java/com/dropbox/core/RateLimitException.java
+++ b/core/src/main/java/com/dropbox/core/RateLimitException.java
@@ -2,6 +2,9 @@
import java.util.concurrent.TimeUnit;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* The server is overloaded, or you have hit a rate limit. Try again later after the designated
* backoff (see {@link #getBackoffMillis}).
@@ -9,8 +12,7 @@
public class RateLimitException extends RetryException {
private static final long serialVersionUID = 0L;
- public RateLimitException(String requestId, String message, long backoff, TimeUnit unit) {
+ public RateLimitException(@Nullable String requestId, @Nullable String message, long backoff, @Nonnull TimeUnit unit) {
super(requestId, message, backoff, unit);
}
}
-
diff --git a/core/src/main/java/com/dropbox/core/RetryException.java b/core/src/main/java/com/dropbox/core/RetryException.java
index 7d61ce151..1ec63122a 100644
--- a/core/src/main/java/com/dropbox/core/RetryException.java
+++ b/core/src/main/java/com/dropbox/core/RetryException.java
@@ -2,6 +2,9 @@
import java.util.concurrent.TimeUnit;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* A transient exception has occurred and the request should be retried. Clients should only retry
* requests after waiting the requested backoff duration (see {@link #getBackoffMillis}).
@@ -17,7 +20,7 @@ public class RetryException extends DbxException {
* @param requestId ID assigned to request by Dropbox servers
* @param message Error message
*/
- public RetryException(String requestId, String message) {
+ public RetryException(@Nullable String requestId, @Nullable String message) {
this(requestId, message, 0L, TimeUnit.MILLISECONDS);
}
@@ -29,7 +32,7 @@ public RetryException(String requestId, String message) {
* @param backoff amount of time to backoff before retrying the request
* @param unit unit of time for {@code backoff}
*/
- public RetryException(String requestId, String message, long backoff, TimeUnit unit) {
+ public RetryException(@Nullable String requestId, @Nullable String message, long backoff, @Nonnull TimeUnit unit) {
super(requestId, message);
this.backoffMillis = unit.toMillis(backoff);
@@ -45,4 +48,3 @@ public long getBackoffMillis() {
return backoffMillis;
}
}
-
diff --git a/core/src/main/java/com/dropbox/core/ServerException.java b/core/src/main/java/com/dropbox/core/ServerException.java
index b4948c0e1..6d2c44887 100644
--- a/core/src/main/java/com/dropbox/core/ServerException.java
+++ b/core/src/main/java/com/dropbox/core/ServerException.java
@@ -1,5 +1,8 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* The server said that something went wrong on its end (HTTP 500 error code).
* This indicates bug on the Dropbox server, but there are multiple potential causes.
@@ -26,8 +29,7 @@
public class ServerException extends DbxException {
private static final long serialVersionUID = 0;
- public ServerException(String requestId, String message) {
+ public ServerException(@Nullable String requestId, @Nullable String message) {
super(requestId, message);
}
}
-
diff --git a/core/src/main/java/com/dropbox/core/TokenAccessType.java b/core/src/main/java/com/dropbox/core/TokenAccessType.java
index 15a73dfe0..05772a70b 100644
--- a/core/src/main/java/com/dropbox/core/TokenAccessType.java
+++ b/core/src/main/java/com/dropbox/core/TokenAccessType.java
@@ -1,5 +1,7 @@
package com.dropbox.core;
+import javax.annotation.Nonnull;
+
/**
* Whether or not to include refresh token in {@link DbxAuthFinish}
* Non-mobile apps use it in {@link DbxWebAuth}.
@@ -15,14 +17,14 @@ public enum TokenAccessType{
*/
OFFLINE("offline");
- private String string;
+ private @Nonnull String string;
- TokenAccessType(String string) {
+ TokenAccessType(@Nonnull String string) {
this.string = string;
}
@Override
- public String toString() {
+ public @Nonnull String toString() {
return string;
}
}
diff --git a/core/src/main/java/com/dropbox/core/http/GoogleAppEngineRequestor.java b/core/src/main/java/com/dropbox/core/http/GoogleAppEngineRequestor.java
index 5a513f7a9..02e835bf8 100644
--- a/core/src/main/java/com/dropbox/core/http/GoogleAppEngineRequestor.java
+++ b/core/src/main/java/com/dropbox/core/http/GoogleAppEngineRequestor.java
@@ -19,7 +19,9 @@
import com.google.appengine.api.urlfetch.URLFetchService;
import com.google.appengine.api.urlfetch.URLFetchServiceFactory;
-/*>>> import checkers.nullness.quals.Nullable; */
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* {@link HttpRequestor} implementation that uses Google App Engine URL fetch service.
@@ -47,45 +49,45 @@ public GoogleAppEngineRequestor() {
this(newDefaultOptions());
}
- public GoogleAppEngineRequestor(FetchOptions options) {
+ public GoogleAppEngineRequestor(@Nonnull FetchOptions options) {
this(options, URLFetchServiceFactory.getURLFetchService());
}
- public GoogleAppEngineRequestor(FetchOptions options, URLFetchService service) {
+ public GoogleAppEngineRequestor(@Nonnull FetchOptions options, @Nonnull URLFetchService service) {
if (options == null) throw new NullPointerException("options");
if (service == null) throw new NullPointerException("service");
this.options = options;
this.service = service;
}
- public FetchOptions getOptions() {
+ public @Nonnull FetchOptions getOptions() {
return options;
}
- public URLFetchService getService() {
+ public @Nonnull URLFetchService getService() {
return service;
}
@Override
- public Response doGet(String url, Iterable headers) throws IOException {
+ public @Nonnull Response doGet(@Nonnull String url, @Nonnull Iterable headers) throws IOException {
HTTPRequest request = newRequest(url, HTTPMethod.GET, headers);
HTTPResponse response = service.fetch(request);
return toRequestorResponse(response);
}
@Override
- public Uploader startPost(String url, Iterable headers) throws IOException {
+ public @Nonnull Uploader startPost(@Nonnull String url, @Nonnull Iterable headers) throws IOException {
HTTPRequest request = newRequest(url, HTTPMethod.POST, headers);
return new FetchServiceUploader(service, request, new ByteArrayOutputStream());
}
@Override
- public Uploader startPut(String url, Iterable headers) throws IOException {
+ public @Nonnull Uploader startPut(@Nonnull String url, @Nonnull Iterable headers) throws IOException {
HTTPRequest request = newRequest(url, HTTPMethod.POST, headers);
return new FetchServiceUploader(service, request, new ByteArrayOutputStream());
}
- private HTTPRequest newRequest(String url, HTTPMethod method, Iterable headers) throws IOException {
+ private @Nonnull HTTPRequest newRequest(@Nonnull String url, @Nonnull HTTPMethod method, @Nonnull Iterable headers) throws IOException {
HTTPRequest request = new HTTPRequest(new URL(url), method, options);
for (Header header : headers) {
request.addHeader(new HTTPHeader(header.getKey(), header.getValue()));
@@ -99,7 +101,7 @@ private HTTPRequest newRequest(String url, HTTPMethod method, Iterable h
*
* @return new instance of default fetch options used by this requestor.
*/
- public static FetchOptions newDefaultOptions() {
+ public static @Nonnull FetchOptions newDefaultOptions() {
return FetchOptions.Builder.withDefaults()
.validateCertificate()
.doNotFollowRedirects()
@@ -108,7 +110,7 @@ public static FetchOptions newDefaultOptions() {
.setDeadline((DEFAULT_CONNECT_TIMEOUT_MILLIS + DEFAULT_READ_TIMEOUT_MILLIS)/1000.0);
}
- private static Response toRequestorResponse(HTTPResponse response) {
+ private static @Nonnull Response toRequestorResponse(@Nonnull HTTPResponse response) {
Map> headers = new HashMap>();
for (HTTPHeader header : response.getHeadersUncombined()) {
List existing = headers.get(header.getName());
@@ -128,16 +130,18 @@ private static class FetchServiceUploader extends Uploader {
private final URLFetchService service;
private final ByteArrayOutputStream body;
- private HTTPRequest request;
+ private @Nullable HTTPRequest request;
- public FetchServiceUploader(URLFetchService service, HTTPRequest request, ByteArrayOutputStream body) {
+ public FetchServiceUploader(@Nonnull URLFetchService service,
+ @Nonnull HTTPRequest request,
+ @Nonnull ByteArrayOutputStream body) {
this.service = service;
this.request = request;
this.body = body;
}
@Override
- public OutputStream getBody() {
+ public @Nonnull OutputStream getBody() {
return body;
}
@@ -165,16 +169,17 @@ public void abort() {
}
@Override
- public Response finish() throws IOException {
+ public @Nonnull Response finish() throws IOException {
if (request == null) {
throw new IllegalStateException("Uploader already closed.");
}
- request.setPayload(body.toByteArray());
+ byte[] payload = body.toByteArray();
+ request.setPayload(payload);
HTTPResponse response = service.fetch(request);
Response requestorResponse = toRequestorResponse(response);
close();
if (progressListener != null) {
- progressListener.onProgress(request.getPayload().length);
+ progressListener.onProgress(payload.length);
}
return requestorResponse;
}
diff --git a/core/src/main/java/com/dropbox/core/http/HttpRequestor.java b/core/src/main/java/com/dropbox/core/http/HttpRequestor.java
index 8a23d0790..a4be27b62 100644
--- a/core/src/main/java/com/dropbox/core/http/HttpRequestor.java
+++ b/core/src/main/java/com/dropbox/core/http/HttpRequestor.java
@@ -14,6 +14,9 @@
import com.dropbox.core.util.IOUtil;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
/**
* An interface that the Dropbox client library uses to make HTTP requests.
* If you're fine with the standard Java {@link java.net.HttpURLConnection}
@@ -36,12 +39,12 @@ public abstract class HttpRequestor
// server.
public static final long DEFAULT_READ_TIMEOUT_MILLIS = TimeUnit.MINUTES.toMillis(2);
- public abstract Response doGet(String url, Iterable headers) throws IOException;
- public abstract Uploader startPost(String url, Iterable headers) throws IOException;
- public Uploader startPostInStreamingMode(String url, Iterable headers) throws IOException {
+ public abstract @Nonnull Response doGet(@Nonnull String url, @Nonnull Iterable headers) throws IOException;
+ public abstract @Nonnull Uploader startPost(@Nonnull String url, @Nonnull Iterable headers) throws IOException;
+ public @Nonnull Uploader startPostInStreamingMode(@Nonnull String url, @Nonnull Iterable headers) throws IOException {
return startPost(url, headers);
}
- public abstract Uploader startPut(String url, Iterable headers) throws IOException;
+ public abstract @Nonnull Uploader startPut(@Nonnull String url, @Nonnull Iterable headers) throws IOException;
/**
* A simple structure holding an HTTP header, which is key/value pair.
@@ -51,7 +54,7 @@ public static final class Header {
private final String key;
private final String value;
- public Header(String key, String value) {
+ public Header(@Nonnull String key, @Nonnull String value) {
this.key = key;
this.value = value;
}
@@ -61,7 +64,7 @@ public Header(String key, String value) {
*
* @return header name
*/
- public String getKey() {
+ public @Nonnull String getKey() {
return key;
}
@@ -70,20 +73,20 @@ public String getKey() {
*
* @return header value
*/
- public String getValue() {
+ public @Nonnull String getValue() {
return value;
}
}
public static abstract class Uploader {
- protected IOUtil.ProgressListener progressListener;
+ protected @Nullable IOUtil.ProgressListener progressListener;
- public abstract OutputStream getBody();
+ public abstract @Nonnull OutputStream getBody();
public abstract void close();
public abstract void abort();
- public abstract Response finish() throws IOException;
+ public abstract @Nonnull Response finish() throws IOException;
- public void upload(File file) throws IOException {
+ public void upload(@Nonnull File file) throws IOException {
try {
upload(new FileInputStream(file));
} catch (IOUtil.ReadException ex) {
@@ -93,11 +96,11 @@ public void upload(File file) throws IOException {
}
}
- public void upload(InputStream in, long limit) throws IOException {
+ public void upload(@Nonnull InputStream in, long limit) throws IOException {
upload(IOUtil.limit(in, limit));
}
- public void upload(InputStream in) throws IOException {
+ public void upload(@Nonnull InputStream in) throws IOException {
OutputStream out = getBody();
try {
IOUtil.copyStreamToStream(in, out);
@@ -106,7 +109,7 @@ public void upload(InputStream in) throws IOException {
}
}
- public void upload(byte [] body) throws IOException {
+ public void upload(@Nonnull byte [] body) throws IOException {
OutputStream out = getBody();
try {
out.write(body);
@@ -115,17 +118,17 @@ public void upload(byte [] body) throws IOException {
}
}
- public void setProgressListener(IOUtil.ProgressListener progressListener) {
+ public void setProgressListener(@Nullable IOUtil.ProgressListener progressListener) {
this.progressListener = progressListener;
}
}
public static final class Response {
private final int statusCode;
- private final InputStream body;
+ private final @Nullable InputStream body;
private final Map> headers;
- public Response(int statusCode, InputStream body, Map> headers) {
+ public Response(int statusCode, @Nullable InputStream body, @Nonnull Map> headers) {
this.statusCode = statusCode;
this.body = body;
this.headers = asUnmodifiableCaseInsensitiveMap(headers);
@@ -147,7 +150,7 @@ public int getStatusCode() {
*
* @return HTTP response body
*/
- public InputStream getBody() {
+ public @Nullable InputStream getBody() {
return body;
}
@@ -156,11 +159,12 @@ public InputStream getBody() {
*
* @return case-insensitive, unmodifiable headers
*/
- public Map> getHeaders() {
+ public @Nonnull Map> getHeaders() {
return headers;
}
- private static final Map> asUnmodifiableCaseInsensitiveMap(Map> original) {
+ private static @Nonnull Map> asUnmodifiableCaseInsensitiveMap(
+ @Nonnull Map> original) {
Map> insensitive = new TreeMap>(String.CASE_INSENSITIVE_ORDER);
for (Map.Entry> entry : original.entrySet()) {
// Java HttpURLConnection puts status line as the 'null' key, e.g.:
diff --git a/core/src/main/java/com/dropbox/core/http/OkHttp3Requestor.java b/core/src/main/java/com/dropbox/core/http/OkHttp3Requestor.java
index 8978c45ba..803abd6c5 100644
--- a/core/src/main/java/com/dropbox/core/http/OkHttp3Requestor.java
+++ b/core/src/main/java/com/dropbox/core/http/OkHttp3Requestor.java
@@ -19,9 +19,11 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
import okio.*;
-/*>>> import checkers.nullness.quals.Nullable; */
/**
* {@link HttpRequestor} implementation that uses OkHttp
@@ -31,14 +33,14 @@ public class OkHttp3Requestor extends HttpRequestor {
/**
* Returns an {@code OkHttpClient} instance with the default settings for this SDK.
*/
- public static OkHttpClient defaultOkHttpClient() {
+ public static @Nonnull OkHttpClient defaultOkHttpClient() {
return defaultOkHttpClientBuilder().build();
}
/**
* Returns an {@code OkHttpClient.Builder} instance with the default settings for this SDK.
*/
- public static OkHttpClient.Builder defaultOkHttpClientBuilder() {
+ public static @Nonnull OkHttpClient.Builder defaultOkHttpClientBuilder() {
return new OkHttpClient.Builder()
.connectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
.readTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
@@ -67,7 +69,7 @@ public static OkHttpClient.Builder defaultOkHttpClientBuilder() {
*
*
*/
- public OkHttp3Requestor(OkHttpClient client) {
+ public OkHttp3Requestor(@Nonnull OkHttpClient client) {
if (client == null) throw new NullPointerException("client");
OkHttpUtil.assertNotSameThreadExecutor(client.dispatcher().executorService());
this.client = client;
@@ -81,7 +83,7 @@ public OkHttp3Requestor(OkHttpClient client) {
*
* @return underlying {@code OkHttpClient} used by this requestor.
*/
- public OkHttpClient getClient() {
+ public @Nonnull OkHttpClient getClient() {
return client;
}
@@ -93,7 +95,7 @@ public OkHttpClient getClient() {
*
* @param request Builder of request to be executed
*/
- protected void configureRequest(Request.Builder request) { }
+ protected void configureRequest(@Nonnull Request.Builder request) { }
/**
* Called before returning {@link Response} from a request.
@@ -107,12 +109,12 @@ protected void configureRequest(Request.Builder request) { }
*
* @return OkHttp response
*/
- protected okhttp3.Response interceptResponse(okhttp3.Response response) {
+ protected @Nonnull okhttp3.Response interceptResponse(@Nonnull okhttp3.Response response) {
return response;
}
@Override
- public Response doGet(String url, Iterable headers) throws IOException {
+ public @Nonnull Response doGet(@Nonnull String url, @Nonnull Iterable headers) throws IOException {
Request.Builder builder = new Request.Builder().get().url(url);
toOkHttpHeaders(headers, builder);
configureRequest(builder);
@@ -123,29 +125,33 @@ public Response doGet(String url, Iterable headers) throws IOException {
}
@Override
- public HttpRequestor.Uploader startPost(String url, Iterable headers) throws IOException {
+ public @Nonnull HttpRequestor.Uploader startPost(@Nonnull String url,
+ @Nonnull Iterable headers) throws IOException {
return startUpload(url, headers, "POST");
}
@Override
- public HttpRequestor.Uploader startPut(String url, Iterable