Skip to content

Commit 0cfc67e

Browse files
authored
Cleanup (#861)
* Remove unneeded throws calls and remove some deprecated methods * Fix lint warnings, including javadocs, redundant initializers, and more * Remove some outdated things from the contributing doc * Fix potential null pointer exception within the push broadcast receiver * Add findAll to ktx and make extension functions inline * Remove more unused methods and inspection warnings * Update dependencies and remove unused class
1 parent 4030884 commit 0cfc67e

File tree

112 files changed

+728
-1174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+728
-1174
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Contributing to Parse SDK for Android
22
We want to make contributing to this project as easy and transparent as possible.
33

4-
## Code of Conduct
5-
Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read [the full text](https://code.facebook.com/codeofconduct) so that you can understand what actions will and will not be tolerated.
6-
74
## Our Development Process
85
Most of our work will be done in public directly on GitHub. There may be changes done through our internal source control, but it will be rare and only as needed.
96

@@ -18,12 +15,6 @@ We actively welcome your pull requests. When we get one, we'll run some Parse-sp
1815
3. If you've changed APIs, update the documentation.
1916
4. Ensure the test suite passes.
2017
5. Make sure your code lints.
21-
6. If you haven't already, complete the Contributor License Agreement ("CLA").
22-
23-
### Contributor License Agreement ("CLA")
24-
In order to accept your pull request, we need you to submit a CLA. You only need to do this once to work on any of Facebook's open source projects.
25-
26-
Complete your CLA here: <https://developers.facebook.com/opensource/cla>
2718

2819
## Bugs
2920
Although we try to keep developing on Parse easy, you still may run into some issues. Technical questions should be asked on [Stack Overflow][stack-overflow], and for everything else we'll be using GitHub issues.
@@ -44,14 +35,8 @@ Details are key. The more information you provide us the easier it'll be for us
4435
* [Stacktrace or GTFO][stacktrace-or-gtfo]. In all honesty, full stacktraces with line numbers make a happy developer.
4536
* Anything else you find relevant.
4637

47-
### Security Bugs
48-
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe disclosure of security bugs. In those cases, please go through the process outlined on that page and do not file a public issue.
49-
50-
## Style Guide
51-
We're still working on providing a code style for your IDE and getting a linter on GitHub, but for now try to keep the following:
52-
53-
* Most importantly, match the existing code style as much as possible.
54-
* Try to keep lines under 100 characters, if possible.
38+
## Code of Conduct
39+
This project adheres to the [Contributor Covenant Code of Conduct](https://github.com/parse-community/parse-server/blob/master/CODE_OF_CONDUCT.md). By participating, you are expected to honor this code.
5540

5641
## License
5742
By contributing to Parse Android SDK, you agree that your contributions will be licensed under its license.
@@ -60,6 +45,6 @@ By contributing to Parse Android SDK, you agree that your contributions will be
6045
[bug-reports]: https://github.com/parse-community/parse-server
6146
[rest-api]: http://docs.parseplatform.org/rest/guide/
6247
[network-debugging-tool]: https://github.com/square/okhttp/wiki/Interceptors
63-
[parse-api-console]: http://blog.parse.com/announcements/introducing-the-parse-api-console/
48+
[parse-api-console]: http://blog.parseplatform.org/announcements/introducing-the-parse-api-console/
6449
[stacktrace-or-gtfo]: http://i.imgur.com/jacoj.jpg
65-
[tests-dir]: /Parse/src/test/java/com/parse
50+
[tests-dir]: /parse/src/test/java/com/parse

fcm/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ android {
3131
}
3232

3333
dependencies {
34-
api "com.google.firebase:firebase-messaging:15.0.2"
34+
api "com.google.firebase:firebase-messaging:17.1.0"
3535
api "com.firebase:firebase-jobdispatcher:$firebaseJobdispatcherVersion"
3636
implementation project(':parse')
3737
}

gcm/src/main/java/com/parse/gcm/ParseGCMJobService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public boolean onStartJob(final JobParameters job) {
5858

5959
Task.callInBackground(new Callable<Void>() {
6060
@Override
61-
public Void call() throws Exception {
61+
public Void call() {
6262
try {
6363
InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
6464
String senderId = job.getExtras().getString(KEY_GCM_SENDER_ID);

ktx/src/main/java/com/parse/ktx/ParseObject.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@file:Suppress("unused")
1+
@file:Suppress("unused", "NOTHING_TO_INLINE")
22

33
package com.parse.ktx
44

@@ -11,7 +11,7 @@ import com.parse.ParseObject
1111
* @return the value
1212
*/
1313
@Suppress("UNCHECKED_CAST")
14-
fun <T> ParseObject.getAs(key: String): T = get(key) as T
14+
inline fun <T> ParseObject.getAs(key: String): T = get(key) as T
1515

1616
/**
1717
* Get the object optionally as null. This has a chance of throwing an exception if the object
@@ -20,7 +20,7 @@ fun <T> ParseObject.getAs(key: String): T = get(key) as T
2020
* @return the value, or null if nothing is there
2121
*/
2222
@Suppress("UNCHECKED_CAST")
23-
fun <T> ParseObject.getAsOrNull(key: String): T? {
23+
inline fun <T> ParseObject.getAsOrNull(key: String): T? {
2424
if (containsKey(key)) {
2525
return get(key) as T?
2626
}
@@ -30,7 +30,7 @@ fun <T> ParseObject.getAsOrNull(key: String): T? {
3030
/**
3131
* [ParseObject.put] the value, doing nothing if the value is null
3232
*/
33-
fun ParseObject.putOrIgnore(key: String, value: Any?) {
33+
inline fun ParseObject.putOrIgnore(key: String, value: Any?) {
3434
if (value != null) {
3535
put(key, value)
3636
}
@@ -39,7 +39,7 @@ fun ParseObject.putOrIgnore(key: String, value: Any?) {
3939
/**
4040
* [ParseObject.put] the value, or [ParseObject.remove] it if the value is null
4141
*/
42-
fun ParseObject.putOrRemove(key: String, value: Any?) {
42+
inline fun ParseObject.putOrRemove(key: String, value: Any?) {
4343
if (value == null) {
4444
remove(key)
4545
} else {
@@ -52,7 +52,7 @@ fun ParseObject.putOrRemove(key: String, value: Any?) {
5252
* @param key the key
5353
* @return the value, or null if nothing is there
5454
*/
55-
fun ParseObject.getBooleanOrNull(key: String): Boolean? {
55+
inline fun ParseObject.getBooleanOrNull(key: String): Boolean? {
5656
if (containsKey(key)) {
5757
return getBoolean(key)
5858
}
@@ -64,7 +64,7 @@ fun ParseObject.getBooleanOrNull(key: String): Boolean? {
6464
* @param key the key
6565
* @return the value, or null if nothing is there
6666
*/
67-
fun ParseObject.getIntOrNull(key: String): Int? {
67+
inline fun ParseObject.getIntOrNull(key: String): Int? {
6868
return getNumber(key)?.toInt()
6969
}
7070

@@ -73,7 +73,7 @@ fun ParseObject.getIntOrNull(key: String): Int? {
7373
* @param key the key
7474
* @return the value, or null if nothing is there
7575
*/
76-
fun ParseObject.getLongOrNull(key: String): Long? {
76+
inline fun ParseObject.getLongOrNull(key: String): Long? {
7777
return getNumber(key)?.toLong()
7878
}
7979

@@ -82,6 +82,6 @@ fun ParseObject.getLongOrNull(key: String): Long? {
8282
* @param key the key
8383
* @return the value, or null if nothing is there
8484
*/
85-
fun ParseObject.getDoubleOrNull(key: String): Double? {
85+
inline fun ParseObject.getDoubleOrNull(key: String): Double? {
8686
return getNumber(key)?.toDouble()
8787
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@file:Suppress("NOTHING_TO_INLINE", "unused")
2+
3+
package com.parse.ktx
4+
5+
import com.parse.ParseException
6+
import com.parse.ParseObject
7+
import com.parse.ParseQuery
8+
9+
/**
10+
* Parse hard limits [ParseQuery.find] to [ParseQuery.MAX_LIMIT] objects. This will fetch absolutely all the
11+
* objects. Use with caution, since you could potentially run out of memory if your query is too large.
12+
* Note that this will modify the current limit of the query
13+
*/
14+
@Throws(ParseException::class)
15+
inline fun <T: ParseObject> ParseQuery<T>.findAll(): List<T> {
16+
limit = ParseQuery.MAX_LIMIT
17+
val list = mutableListOf<T>()
18+
try {
19+
while (true) {
20+
val result = find()
21+
list.addAll(result)
22+
if (result.size < ParseQuery.MAX_LIMIT) {
23+
break
24+
} else {
25+
setSkip(skip + ParseQuery.MAX_LIMIT)
26+
}
27+
}
28+
return list
29+
} catch (ex : ParseException) {
30+
if (ex.code == ParseException.OBJECT_NOT_FOUND) {
31+
return list
32+
}
33+
throw ex
34+
}
35+
}

parse/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies {
3737
api 'com.parse.bolts:bolts-tasks:1.4.0'
3838
api "com.squareup.okhttp3:okhttp:$okhttpVersion"
3939

40-
testImplementation 'org.robolectric:robolectric:3.3.2'
40+
testImplementation 'org.robolectric:robolectric:3.8'
4141
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
4242
testImplementation 'org.mockito:mockito-core:1.10.19'
4343
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttpVersion"

parse/src/main/java/com/parse/CacheQueryController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private <TResult> Task<TResult> runCommandWithPolicyAsync(final CommandDelegate<
131131
return c.runFromCacheAsync().continueWithTask(new Continuation<TResult, Task<TResult>>() {
132132
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
133133
@Override
134-
public Task<TResult> then(Task<TResult> task) throws Exception {
134+
public Task<TResult> then(Task<TResult> task) {
135135
if (task.getError() instanceof ParseException) {
136136
return c.runOnNetworkAsync();
137137
}
@@ -142,7 +142,7 @@ public Task<TResult> then(Task<TResult> task) throws Exception {
142142
return c.runOnNetworkAsync().continueWithTask(new Continuation<TResult, Task<TResult>>() {
143143
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
144144
@Override
145-
public Task<TResult> then(Task<TResult> task) throws Exception {
145+
public Task<TResult> then(Task<TResult> task) {
146146
Exception error = task.getError();
147147
if (error instanceof ParseException &&
148148
((ParseException) error).getCode() == ParseException.CONNECTION_FAILED) {

parse/src/main/java/com/parse/CachedCurrentInstallationController.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public Task<Void> setAsync(final ParseInstallation installation) {
5050

5151
return taskQueue.enqueue(new Continuation<Void, Task<Void>>() {
5252
@Override
53-
public Task<Void> then(Task<Void> toAwait) throws Exception {
53+
public Task<Void> then(Task<Void> toAwait) {
5454
return toAwait.continueWithTask(new Continuation<Void, Task<Void>>() {
5555
@Override
56-
public Task<Void> then(Task<Void> task) throws Exception {
56+
public Task<Void> then(Task<Void> task) {
5757
return store.setAsync(installation);
5858
}
5959
}).continueWithTask(new Continuation<Void, Task<Void>>() {
6060
@Override
61-
public Task<Void> then(Task<Void> task) throws Exception {
61+
public Task<Void> then(Task<Void> task) {
6262
installationId.set(installation.getInstallationId());
6363
return task;
6464
}
@@ -77,10 +77,10 @@ public Task<ParseInstallation> getAsync() {
7777

7878
return taskQueue.enqueue(new Continuation<Void, Task<ParseInstallation>>() {
7979
@Override
80-
public Task<ParseInstallation> then(Task<Void> toAwait) throws Exception {
80+
public Task<ParseInstallation> then(Task<Void> toAwait) {
8181
return toAwait.continueWithTask(new Continuation<Void, Task<ParseInstallation>>() {
8282
@Override
83-
public Task<ParseInstallation> then(Task<Void> task) throws Exception {
83+
public Task<ParseInstallation> then(Task<Void> task) {
8484
synchronized (mutex) {
8585
if (currentInstallation != null) {
8686
return Task.forResult(currentInstallation);
@@ -89,7 +89,7 @@ public Task<ParseInstallation> then(Task<Void> task) throws Exception {
8989

9090
return store.getAsync().continueWith(new Continuation<ParseInstallation, ParseInstallation>() {
9191
@Override
92-
public ParseInstallation then(Task<ParseInstallation> task) throws Exception {
92+
public ParseInstallation then(Task<ParseInstallation> task) {
9393
ParseInstallation current = task.getResult();
9494
if (current == null) {
9595
current = ParseObject.create(ParseInstallation.class);
@@ -121,10 +121,10 @@ public Task<Boolean> existsAsync() {
121121

122122
return taskQueue.enqueue(new Continuation<Void, Task<Boolean>>() {
123123
@Override
124-
public Task<Boolean> then(Task<Void> toAwait) throws Exception {
124+
public Task<Boolean> then(Task<Void> toAwait) {
125125
return toAwait.continueWithTask(new Continuation<Void, Task<Boolean>>() {
126126
@Override
127-
public Task<Boolean> then(Task<Void> task) throws Exception {
127+
public Task<Boolean> then(Task<Void> task) {
128128
return store.existsAsync();
129129
}
130130
});

parse/src/main/java/com/parse/CachedCurrentUserController.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public CachedCurrentUserController(ParseObjectStore<ParseUser> store) {
4242
public Task<Void> setAsync(final ParseUser user) {
4343
return taskQueue.enqueue(new Continuation<Void, Task<Void>>() {
4444
@Override
45-
public Task<Void> then(Task<Void> toAwait) throws Exception {
45+
public Task<Void> then(Task<Void> toAwait) {
4646
return toAwait.continueWithTask(new Continuation<Void, Task<Void>>() {
4747
@Override
48-
public Task<Void> then(Task<Void> task) throws Exception {
48+
public Task<Void> then(Task<Void> task) {
4949
ParseUser oldCurrentUser;
5050
synchronized (mutex) {
5151
oldCurrentUser = currentUser;
@@ -56,7 +56,7 @@ public Task<Void> then(Task<Void> task) throws Exception {
5656
// We don't need to remove persisted files since we're overwriting them
5757
return oldCurrentUser.logOutAsync(false).continueWith(new Continuation<Void, Void>() {
5858
@Override
59-
public Void then(Task<Void> task) throws Exception {
59+
public Void then(Task<Void> task) {
6060
return null; // ignore errors
6161
}
6262
});
@@ -65,16 +65,16 @@ public Void then(Task<Void> task) throws Exception {
6565
}
6666
}).onSuccessTask(new Continuation<Void, Task<Void>>() {
6767
@Override
68-
public Task<Void> then(Task<Void> task) throws Exception {
68+
public Task<Void> then(Task<Void> task) {
6969
user.setIsCurrentUser(true);
7070
return user.synchronizeAllAuthDataAsync();
7171
}
7272
}).onSuccessTask(new Continuation<Void, Task<Void>>() {
7373
@Override
74-
public Task<Void> then(Task<Void> task) throws Exception {
74+
public Task<Void> then(Task<Void> task) {
7575
return store.setAsync(user).continueWith(new Continuation<Void, Void>() {
7676
@Override
77-
public Void then(Task<Void> task) throws Exception {
77+
public Void then(Task<Void> task) {
7878
synchronized (mutex) {
7979
currentUserMatchesDisk = !task.isFaulted();
8080
currentUser = user;
@@ -114,10 +114,10 @@ public Task<Boolean> existsAsync() {
114114

115115
return taskQueue.enqueue(new Continuation<Void, Task<Boolean>>() {
116116
@Override
117-
public Task<Boolean> then(Task<Void> toAwait) throws Exception {
117+
public Task<Boolean> then(Task<Void> toAwait) {
118118
return toAwait.continueWithTask(new Continuation<Void, Task<Boolean>>() {
119119
@Override
120-
public Task<Boolean> then(Task<Void> task) throws Exception {
120+
public Task<Boolean> then(Task<Void> task) {
121121
return store.existsAsync();
122122
}
123123
});
@@ -157,7 +157,7 @@ public void clearFromDisk() {
157157
public Task<String> getCurrentSessionTokenAsync() {
158158
return getAsync(false).onSuccess(new Continuation<ParseUser, String>() {
159159
@Override
160-
public String then(Task<ParseUser> task) throws Exception {
160+
public String then(Task<ParseUser> task) {
161161
ParseUser user = task.getResult();
162162
return user != null ? user.getSessionToken() : null;
163163
}
@@ -168,16 +168,16 @@ public String then(Task<ParseUser> task) throws Exception {
168168
public Task<Void> logOutAsync() {
169169
return taskQueue.enqueue(new Continuation<Void, Task<Void>>() {
170170
@Override
171-
public Task<Void> then(Task<Void> toAwait) throws Exception {
171+
public Task<Void> then(Task<Void> toAwait) {
172172
// We can parallelize disk and network work, but only after we restore the current user from
173173
// disk.
174174
final Task<ParseUser> userTask = getAsync(false);
175175
return Task.whenAll(Arrays.asList(userTask, toAwait)).continueWithTask(new Continuation<Void, Task<Void>>() {
176176
@Override
177-
public Task<Void> then(Task<Void> task) throws Exception {
177+
public Task<Void> then(Task<Void> task) {
178178
Task<Void> logOutTask = userTask.onSuccessTask(new Continuation<ParseUser, Task<Void>>() {
179179
@Override
180-
public Task<Void> then(Task<ParseUser> task) throws Exception {
180+
public Task<Void> then(Task<ParseUser> task) {
181181
ParseUser user = task.getResult();
182182
if (user == null) {
183183
return task.cast();
@@ -188,7 +188,7 @@ public Task<Void> then(Task<ParseUser> task) throws Exception {
188188

189189
Task<Void> diskTask = store.deleteAsync().continueWith(new Continuation<Void, Void>() {
190190
@Override
191-
public Void then(Task<Void> task) throws Exception {
191+
public Void then(Task<Void> task) {
192192
boolean deleted = !task.isFaulted();
193193
synchronized (mutex) {
194194
currentUserMatchesDisk = deleted;
@@ -214,10 +214,10 @@ public Task<ParseUser> getAsync(final boolean shouldAutoCreateUser) {
214214

215215
return taskQueue.enqueue(new Continuation<Void, Task<ParseUser>>() {
216216
@Override
217-
public Task<ParseUser> then(Task<Void> toAwait) throws Exception {
217+
public Task<ParseUser> then(Task<Void> toAwait) {
218218
return toAwait.continueWithTask(new Continuation<Void, Task<ParseUser>>() {
219219
@Override
220-
public Task<ParseUser> then(Task<Void> ignored) throws Exception {
220+
public Task<ParseUser> then(Task<Void> ignored) {
221221
ParseUser current;
222222
boolean matchesDisk;
223223
synchronized (mutex) {
@@ -238,7 +238,7 @@ public Task<ParseUser> then(Task<Void> ignored) throws Exception {
238238

239239
return store.getAsync().continueWith(new Continuation<ParseUser, ParseUser>() {
240240
@Override
241-
public ParseUser then(Task<ParseUser> task) throws Exception {
241+
public ParseUser then(Task<ParseUser> task) {
242242
ParseUser current = task.getResult();
243243
boolean matchesDisk = !task.isFaulted();
244244

0 commit comments

Comments
 (0)