Skip to content

Commit bcc1134

Browse files
committed
Not allowing setObjectId() in ParseInstallation
1 parent 0579589 commit bcc1134

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Parse/src/main/java/com/parse/ParseInstallation.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public String getInstallationId() {
9494
return getString(KEY_INSTALLATION_ID);
9595
}
9696

97+
@Override
98+
public void setObjectId(String newObjectId) {
99+
throw new RuntimeException("Installation's objectId cannot be changed");
100+
}
101+
97102
@Override
98103
/* package */ boolean needsDefaultACL() {
99104
return false;
@@ -149,7 +154,7 @@ public Task<Void> then(Task<Void> task) throws Exception {
149154
&& task.getError() instanceof ParseException
150155
&& ((ParseException) task.getError()).getCode() == ParseException.OBJECT_NOT_FOUND) {
151156
synchronized (mutex) {
152-
setObjectId(null);
157+
setState(new State.Builder(getState()).objectId(null).build());
153158
markAllFieldsDirty();
154159
return ParseInstallation.super.saveAsync(sessionToken, toAwait);
155160
}

Parse/src/test/java/com/parse/ParseInstallationTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,19 @@ public void testLocaleIdentifierSpecialCases() throws Exception {
323323
assertEquals("en", installation.getString(KEY_LOCALE_IDENTIFIER));
324324
}
325325

326+
@Test(expected = RuntimeException.class)
327+
public void testSetObjectId() throws Exception {
328+
ParseCurrentInstallationController controller =
329+
mock(ParseCurrentInstallationController.class);
330+
ParseInstallation currentInstallation = new ParseInstallation();
331+
when(controller.getAsync()).thenReturn(Task.forResult(currentInstallation));
332+
ParseCorePlugins.getInstance().registerCurrentInstallationController(controller);
326333

334+
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
335+
assertNotNull(installation);
336+
verify(controller, times(1)).getAsync();
337+
installation.setObjectId(null);
338+
}
327339

328340
// TODO(mengyan): Add testFetchAsync, right now we can not test super methods inside
329341
// testFetchAsync

0 commit comments

Comments
 (0)