Skip to content
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

Avoid depending on reference equality of interned strings and literals; this seems to fail sometimes on Android #367

Merged
merged 2 commits into from
Mar 1, 2018
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
2 changes: 1 addition & 1 deletion lib/src/main/java/io/ably/lib/types/BaseMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public JsonElement serialize(BaseMessage message, Type typeOfMessage, JsonSerial
if(message.clientId != null) json.addProperty("clientId", message.clientId);
if(message.connectionId != null) json.addProperty("connectionId", message.connectionId);
return json;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these due to a change of IDE?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of - I saw those as I was looking through the code last night and fixed them. So they were explicit changes, but I noticed them because of a change of IDE.

}

/* Msgpack processing */
Expand Down
42 changes: 25 additions & 17 deletions lib/src/main/java/io/ably/lib/types/ConnectionDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,31 @@ ConnectionDetails readMsgpack(MessageUnpacker unpacker) throws IOException {
MessageFormat fieldFormat = unpacker.getNextFormat();
if(fieldFormat.equals(MessageFormat.NIL)) { unpacker.unpackNil(); continue; }

if(fieldName == "clientId") {
clientId = unpacker.unpackString();
} else if(fieldName == "connectionKey") {
connectionKey = unpacker.unpackString();
} else if(fieldName == "serverId") {
serverId = unpacker.unpackString();
} else if(fieldName == "maxMessageSize") {
maxMessageSize = unpacker.unpackLong();
} else if(fieldName == "maxInboundRate") {
maxInboundRate = unpacker.unpackLong();
} else if(fieldName == "maxFrameSize") {
maxFrameSize = unpacker.unpackLong();
} else if(fieldName == "maxIdleInterval") {
maxIdleInterval = unpacker.unpackLong();
} else {
Log.v(TAG, "Unexpected field: " + fieldName);
unpacker.skipValue();
switch(fieldName) {
case "clientId":
clientId = unpacker.unpackString();
break;
case "connectionKey":
connectionKey = unpacker.unpackString();
break;
case "serverId":
serverId = unpacker.unpackString();
break;
case "maxMessageSize":
maxMessageSize = unpacker.unpackLong();
break;
case "maxInboundRate":
maxInboundRate = unpacker.unpackLong();
break;
case "maxFrameSize":
maxFrameSize = unpacker.unpackLong();
break;
case "maxIdleInterval":
maxIdleInterval = unpacker.unpackLong();
break;
default:
Log.v(TAG, "Unexpected field: " + fieldName);
unpacker.skipValue();
}
}
return this;
Expand Down
22 changes: 13 additions & 9 deletions lib/src/main/java/io/ably/lib/types/ErrorInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ ErrorInfo readMsgpack(MessageUnpacker unpacker) throws IOException {
MessageFormat fieldFormat = unpacker.getNextFormat();
if(fieldFormat.equals(MessageFormat.NIL)) { unpacker.unpackNil(); continue; }

if(fieldName == "message") {
message = unpacker.unpackString();
} else if(fieldName == "code") {
code = unpacker.unpackInt();
} else if(fieldName == "statusCode") {
statusCode = unpacker.unpackInt();
} else {
Log.v(TAG, "Unexpected field: " + fieldName);
unpacker.skipValue();
switch(fieldName) {
case "message":
message = unpacker.unpackString();
break;
case "code":
code = unpacker.unpackInt();
break;
case "statusCode":
statusCode = unpacker.unpackInt();
break;
default:
Log.v(TAG, "Unexpected field: " + fieldName);
unpacker.skipValue();
}
}
return this;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/main/java/io/ably/lib/types/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ Message readMsgpack(MessageUnpacker unpacker) throws IOException {
MessageFormat fieldFormat = unpacker.getNextFormat();
if(fieldFormat.equals(MessageFormat.NIL)) { unpacker.unpackNil(); continue; }

if(super.readField(unpacker, fieldName, fieldFormat)) continue;
if(fieldName == "name") {
if(super.readField(unpacker, fieldName, fieldFormat)) { continue; }
if(fieldName.equals("name")) {
name = unpacker.unpackString();
} else {
Log.v(TAG, "Unexpected field: " + fieldName);
Expand All @@ -102,7 +102,7 @@ public JsonElement serialize(Message message, Type typeOfMessage, JsonSerializat
JsonObject json = (JsonObject)super.serialize(message, typeOfMessage, ctx);
if(message.name != null) json.addProperty("name", message.name);
return json;
}
}
}

private static final String TAG = Message.class.getName();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/io/ably/lib/types/PresenceMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ PresenceMessage readMsgpack(MessageUnpacker unpacker) throws IOException {
MessageFormat fieldFormat = unpacker.getNextFormat();
if(fieldFormat.equals(MessageFormat.NIL)) { unpacker.unpackNil(); continue; }

if(super.readField(unpacker, fieldName, fieldFormat)) continue;
if(fieldName == "action") {
if(super.readField(unpacker, fieldName, fieldFormat)) { continue; }
if(fieldName.equals("action")) {
action = Action.findByValue(unpacker.unpackInt());
} else {
Log.v(TAG, "Unexpected field: " + fieldName);
Expand Down
96 changes: 57 additions & 39 deletions lib/src/main/java/io/ably/lib/types/ProtocolMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,39 +160,55 @@ ProtocolMessage readMsgpack(MessageUnpacker unpacker) throws IOException {
MessageFormat fieldFormat = unpacker.getNextFormat();
if(fieldFormat.equals(MessageFormat.NIL)) { unpacker.unpackNil(); continue; }

if(fieldName == "action") {
action = Action.findByValue(unpacker.unpackInt());
} else if(fieldName == "flags") {
flags = unpacker.unpackInt();
} else if(fieldName == "count") {
count = unpacker.unpackInt();
} else if(fieldName == "error") {
error = ErrorInfo.fromMsgpack(unpacker);
} else if(fieldName == "id") {
id = unpacker.unpackString();
} else if(fieldName == "channel") {
channel = unpacker.unpackString();
} else if(fieldName == "channelSerial") {
channelSerial = unpacker.unpackString();
} else if(fieldName == "connectionId") {
connectionId = unpacker.unpackString();
} else if(fieldName == "connectionSerial") {
connectionSerial = Long.valueOf(unpacker.unpackLong());
} else if(fieldName == "msgSerial") {
msgSerial = Long.valueOf(unpacker.unpackLong());
} else if(fieldName == "timestamp") {
timestamp = unpacker.unpackLong();
} else if(fieldName == "messages") {
messages = MessageSerializer.readMsgpackArray(unpacker);
} else if(fieldName == "presence") {
presence = PresenceSerializer.readMsgpackArray(unpacker);
} else if(fieldName == "connectionDetails") {
connectionDetails = ConnectionDetails.fromMsgpack(unpacker);
} else if(fieldName == "auth") {
auth = AuthDetails.fromMsgpack(unpacker);
} else {
Log.v(TAG, "Unexpected field: " + fieldName);
unpacker.skipValue();
switch(fieldName) {
case "action":
action = Action.findByValue(unpacker.unpackInt());
break;
case "flags":
flags = unpacker.unpackInt();
break;
case "count":
count = unpacker.unpackInt();
break;
case "error":
error = ErrorInfo.fromMsgpack(unpacker);
break;
case "id":
id = unpacker.unpackString();
break;
case "channel":
channel = unpacker.unpackString();
break;
case "channelSerial":
channelSerial = unpacker.unpackString();
break;
case "connectionId":
connectionId = unpacker.unpackString();
break;
case "connectionSerial":
connectionSerial = Long.valueOf(unpacker.unpackLong());
break;
case "msgSerial":
msgSerial = Long.valueOf(unpacker.unpackLong());
break;
case "timestamp":
timestamp = unpacker.unpackLong();
break;
case "messages":
messages = MessageSerializer.readMsgpackArray(unpacker);
break;
case "presence":
presence = PresenceSerializer.readMsgpackArray(unpacker);
break;
case "connectionDetails":
connectionDetails = ConnectionDetails.fromMsgpack(unpacker);
break;
case "auth":
auth = AuthDetails.fromMsgpack(unpacker);
break;
default:
Log.v(TAG, "Unexpected field: " + fieldName);
unpacker.skipValue();
}
}
return this;
Expand All @@ -212,7 +228,7 @@ public Action deserialize(JsonElement json, Type t, JsonDeserializationContext c
@Override
public JsonElement serialize(Action action, Type t, JsonSerializationContext ctx) {
return new JsonPrimitive(action.getValue());
}
}
}

public static class AuthDetails {
Expand All @@ -228,11 +244,13 @@ AuthDetails readMsgpack(MessageUnpacker unpacker) throws IOException {
MessageFormat fieldFormat = unpacker.getNextFormat();
if(fieldFormat.equals(MessageFormat.NIL)) { unpacker.unpackNil(); continue; }

if(fieldName == "accessToken") {
accessToken = unpacker.unpackString();
} else {
Log.v(TAG, "Unexpected field: " + fieldName);
unpacker.skipValue();
switch(fieldName) {
case "accessToken":
accessToken = unpacker.unpackString();
break;
default:
Log.v(TAG, "Unexpected field: " + fieldName);
unpacker.skipValue();
}
}
return this;
Expand Down