Skip to content

Commit cb1101b

Browse files
SyncCredentialsToken: use StandardCharsets, fix lint
StandardCharsets.UTF_8 requires Android SDK 19, which is required since the last ObjectBox Android release.
1 parent 11d04f6 commit cb1101b

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

objectbox-java/src/main/java/io/objectbox/sync/SyncCredentialsToken.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.objectbox.sync;
22

3-
import java.io.UnsupportedEncodingException;
3+
import java.nio.charset.StandardCharsets;
44
import java.util.Arrays;
55

66
import javax.annotation.Nullable;
@@ -21,16 +21,18 @@ public final class SyncCredentialsToken extends SyncCredentials {
2121
this.token = null;
2222
}
2323

24-
SyncCredentialsToken(CredentialsType type, @SuppressWarnings("NullableProblems") byte[] token) {
24+
SyncCredentialsToken(CredentialsType type, byte[] token) {
2525
this(type);
26+
// Annotations do not guarantee non-null values
27+
//noinspection ConstantValue
2628
if (token == null || token.length == 0) {
2729
throw new IllegalArgumentException("Token must not be empty");
2830
}
2931
this.token = token;
3032
}
3133

3234
SyncCredentialsToken(CredentialsType type, String token) {
33-
this(type, asUtf8Bytes(token));
35+
this(type, token.getBytes(StandardCharsets.UTF_8));
3436
}
3537

3638
@Nullable
@@ -56,12 +58,4 @@ public void clear() {
5658
this.token = null;
5759
}
5860

59-
private static byte[] asUtf8Bytes(String token) {
60-
try {
61-
//noinspection CharsetObjectCanBeUsed On Android not available until SDK 19.
62-
return token.getBytes("UTF-8");
63-
} catch (UnsupportedEncodingException e) {
64-
throw new RuntimeException(e);
65-
}
66-
}
6761
}

0 commit comments

Comments
 (0)