Skip to content

Commit bb8eb99

Browse files
add nullability annotations & null check
1 parent 3372171 commit bb8eb99

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

DriveBackup/src/main/java/ratismal/drivebackup/uploaders/onedrive/OneDriveUploader.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ public void uploadFile(java.io.File file, String location) throws IOException {
214214
MessageUtil.sendConsoleException(exception);
215215
setErrorOccurred(true);
216216
}
217-
raf.close();
217+
if (raf != null) {
218+
raf.close();
219+
}
218220
}
219221

220222
/**
@@ -231,7 +233,7 @@ private static class FQID {
231233
public final String driveId;
232234
public final String itemId;
233235

234-
public FQID(String driveId, String itemId) {
236+
public FQID(@NotNull String driveId, @NotNull String itemId) {
235237
this.driveId = driveId;
236238
this.itemId = itemId;
237239
}
@@ -243,7 +245,7 @@ public FQID(String driveId, String itemId) {
243245
* @return the normalized path
244246
*/
245247
@NotNull
246-
private String normalizePath(String path) {
248+
private String normalizePath(@NotNull String path) {
247249
StringBuilder normalized = new StringBuilder();
248250
for (String part : path.split("[/\\\\]")) {
249251
if (".".equals(part) || "..".equals(part)) {
@@ -279,7 +281,7 @@ private String concatPath(@NotNull String lhs, @NotNull String rhs) {
279281
* or if the api request could not be executed due to cancellation, a connectivity problem or timeout.
280282
*/
281283
@NotNull
282-
private FQID createPath(String path) throws IOException {
284+
private FQID createPath(@NotNull String path) throws IOException {
283285
Iterator<String> parts = Arrays.stream(path.split("/")).iterator();
284286
FQID root = createRootFolder(parts.next());
285287
for (; parts.hasNext(); ) {
@@ -298,7 +300,7 @@ private FQID createPath(String path) throws IOException {
298300
* or if the api request could not be executed due to cancellation, a connectivity problem or timeout.
299301
*/
300302
@NotNull
301-
private FQID createFolder(FQID root, String folder) throws IOException {
303+
private FQID createFolder(@NotNull FQID root,@NotNull String folder) throws IOException {
302304
FQID item = getFolder(root, folder);
303305
if (item != null) {
304306
return item;
@@ -329,7 +331,7 @@ private FQID createFolder(FQID root, String folder) throws IOException {
329331
* or if the api request could not be executed due to cancellation, a connectivity problem or timeout.
330332
*/
331333
@NotNull
332-
private FQID createRootFolder(String folder) throws IOException {
334+
private FQID createRootFolder(@NotNull String folder) throws IOException {
333335
FQID item = getRootFolder(folder);
334336
if (item != null) {
335337
return item;
@@ -358,7 +360,7 @@ private FQID createRootFolder(String folder) throws IOException {
358360
* @return FQID or null if not found
359361
*/
360362
@Nullable
361-
private FQID getRootFolder(String folder) {
363+
private FQID getRootFolder(@NotNull String folder) {
362364
try {
363365
String folderUrl = folder.isEmpty() ? folder : ":/" + folder;
364366
Request request = new Request.Builder()
@@ -387,7 +389,7 @@ private FQID getRootFolder(String folder) {
387389
* @return FQID or null if not found
388390
*/
389391
@Nullable
390-
private FQID getFolder(FQID root, String folder) {
392+
private FQID getFolder(@NotNull FQID root,@NotNull String folder) {
391393
try {
392394
Request request = new Request.Builder()
393395
.addHeader("Authorization", "Bearer " + accessToken)
@@ -424,7 +426,7 @@ private FQID getFolder(FQID root, String folder) {
424426
* @param parent the folder containing the files
425427
* @throws Exception
426428
*/
427-
private void pruneBackups(FQID parent) throws Exception {
429+
private void pruneBackups(@NotNull FQID parent) throws Exception {
428430
int fileLimit = ConfigParser.getConfig().backupStorage.keepCount;
429431
if (fileLimit == -1) {
430432
return;
@@ -517,7 +519,7 @@ private void setRanges(@NotNull String[] stringRanges) {
517519
* @return the array of bytes
518520
* @throws IOException
519521
*/
520-
private byte[] getChunk() throws IOException {
522+
private byte @NotNull [] getChunk() throws IOException {
521523
byte[] bytes = new byte[CHUNK_SIZE];
522524
raf.seek(totalUploaded);
523525
int read = raf.read(bytes);

0 commit comments

Comments
 (0)