Skip to content

Not allowing setObjectId() in ParseInstallation #611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Parse/src/main/java/com/parse/ParseInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
public class ParseInstallation extends ParseObject {
private static final String TAG = "com.parse.ParseInstallation";

private static final String KEY_OBJECT_ID = "objectId";
private static final String KEY_INSTALLATION_ID = "installationId";
private static final String KEY_DEVICE_TYPE = "deviceType";
private static final String KEY_APP_NAME = "appName";
Expand All @@ -45,7 +46,7 @@ public class ParseInstallation extends ParseObject {
private static final List<String> READ_ONLY_FIELDS = Collections.unmodifiableList(
Arrays.asList(KEY_DEVICE_TYPE, KEY_INSTALLATION_ID, KEY_DEVICE_TOKEN, KEY_PUSH_TYPE,
KEY_TIME_ZONE, KEY_LOCALE, KEY_APP_VERSION, KEY_APP_NAME, KEY_PARSE_VERSION,
KEY_APP_IDENTIFIER));
KEY_APP_IDENTIFIER, KEY_OBJECT_ID));

// TODO(mengyan): Inject into ParseInstallationInstanceController
/* package */ static ParseCurrentInstallationController getCurrentInstallationController() {
Expand Down Expand Up @@ -94,6 +95,11 @@ public String getInstallationId() {
return getString(KEY_INSTALLATION_ID);
}

@Override
public void setObjectId(String newObjectId) {
throw new RuntimeException("Installation's objectId cannot be changed");
}

@Override
/* package */ boolean needsDefaultACL() {
return false;
Expand Down Expand Up @@ -149,7 +155,7 @@ public Task<Void> then(Task<Void> task) throws Exception {
&& task.getError() instanceof ParseException
&& ((ParseException) task.getError()).getCode() == ParseException.OBJECT_NOT_FOUND) {
synchronized (mutex) {
setObjectId(null);
setState(new State.Builder(getState()).objectId(null).build());
markAllFieldsDirty();
return ParseInstallation.super.saveAsync(sessionToken, toAwait);
}
Expand Down
14 changes: 14 additions & 0 deletions Parse/src/test/java/com/parse/ParseInstallationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ public void testImmutableKeys() {
}
}

@Test (expected = RuntimeException.class)
public void testInstallationObjectIdCannotBeChanged() throws Exception {
boolean hasException = false;
ParseInstallation installation = new ParseInstallation();
try {
installation.put("objectId", "abc");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("Cannot modify"));
hasException = true;
}
assertTrue(hasException);
installation.setObjectId("abc");
}

@Test
public void testSaveAsync() throws Exception {
String sessionToken = "sessionToken";
Expand Down