Skip to content

Commit f5188d6

Browse files
hermanliangrogerhu
authored andcommitted
Not allowing setObjectId() in ParseInstallation (#611)
* Not allowing setObjectId() in ParseInstallation * minor fixes & update test
1 parent 6223d06 commit f5188d6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
public class ParseInstallation extends ParseObject {
3131
private static final String TAG = "com.parse.ParseInstallation";
3232

33+
private static final String KEY_OBJECT_ID = "objectId";
3334
private static final String KEY_INSTALLATION_ID = "installationId";
3435
private static final String KEY_DEVICE_TYPE = "deviceType";
3536
private static final String KEY_APP_NAME = "appName";
@@ -45,7 +46,7 @@ public class ParseInstallation extends ParseObject {
4546
private static final List<String> READ_ONLY_FIELDS = Collections.unmodifiableList(
4647
Arrays.asList(KEY_DEVICE_TYPE, KEY_INSTALLATION_ID, KEY_DEVICE_TOKEN, KEY_PUSH_TYPE,
4748
KEY_TIME_ZONE, KEY_LOCALE, KEY_APP_VERSION, KEY_APP_NAME, KEY_PARSE_VERSION,
48-
KEY_APP_IDENTIFIER));
49+
KEY_APP_IDENTIFIER, KEY_OBJECT_ID));
4950

5051
// TODO(mengyan): Inject into ParseInstallationInstanceController
5152
/* package */ static ParseCurrentInstallationController getCurrentInstallationController() {
@@ -94,6 +95,11 @@ public String getInstallationId() {
9495
return getString(KEY_INSTALLATION_ID);
9596
}
9697

98+
@Override
99+
public void setObjectId(String newObjectId) {
100+
throw new RuntimeException("Installation's objectId cannot be changed");
101+
}
102+
97103
@Override
98104
/* package */ boolean needsDefaultACL() {
99105
return false;
@@ -149,7 +155,7 @@ public Task<Void> then(Task<Void> task) throws Exception {
149155
&& task.getError() instanceof ParseException
150156
&& ((ParseException) task.getError()).getCode() == ParseException.OBJECT_NOT_FOUND) {
151157
synchronized (mutex) {
152-
setObjectId(null);
158+
setState(new State.Builder(getState()).objectId(null).build());
153159
markAllFieldsDirty();
154160
return ParseInstallation.super.saveAsync(sessionToken, toAwait);
155161
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ public void testImmutableKeys() {
106106
}
107107
}
108108

109+
@Test (expected = RuntimeException.class)
110+
public void testInstallationObjectIdCannotBeChanged() throws Exception {
111+
boolean hasException = false;
112+
ParseInstallation installation = new ParseInstallation();
113+
try {
114+
installation.put("objectId", "abc");
115+
} catch (IllegalArgumentException e) {
116+
assertTrue(e.getMessage().contains("Cannot modify"));
117+
hasException = true;
118+
}
119+
assertTrue(hasException);
120+
installation.setObjectId("abc");
121+
}
122+
109123
@Test
110124
public void testSaveAsync() throws Exception {
111125
String sessionToken = "sessionToken";

0 commit comments

Comments
 (0)