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

Discard persisted events with non-nullary constructors #599

Merged
merged 3 commits into from
Sep 11, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions android/src/main/java/io/ably/lib/push/ActivationStateMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,18 @@ private ArrayDeque<ActivationStateMachine.Event> getPersistedPendingEvents() {
try {
String className = activationContext.getPreferences().getString(String.format("%s[%d]", ActivationStateMachine.PersistKeys.PENDING_EVENTS_PREFIX, i), "");
Class<ActivationStateMachine.Event> eventClass = (Class<ActivationStateMachine.Event>) Class.forName(className);
ActivationStateMachine.Event event = eventClass.newInstance();
ActivationStateMachine.Event event;
try {
event = eventClass.newInstance();
Copy link
Member

Choose a reason for hiding this comment

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

You wouldn't prefer an isPersisted() or something on the event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@paddybyers All of them are about to become persistent when #546 is fixed, so we'd then have to find another way to detect "old" persisted stated.

} catch(InstantiationException e) {
// We aren't properly persisting events with a non-nullary constructor. Those events
// are supposed to be handled by states that aren't persisted (until
// https://github.com/ably/ably-java/issues/546 is fixed), so it should be safe to
// just drop them.
Log.d(TAG, String.format("discarding improperly persisted event: %s", className));
continue;
}
deque.add(event);
} catch(InstantiationException e) {
// We aren't properly persisting events with a non-nullary constructor. Those events
// are supposed to be handled by states that aren't persisted (until
// https://github.com/ably/ably-java/issues/546 is fixed), so it should be safe to
// just drop them.
continue;
} catch(Exception e) {
throw new RuntimeException(e);
}
Expand Down