Prevent crash

pull/156/head
M66B 6 years ago
parent 6703cb80ac
commit b13a7d62e2

@ -236,11 +236,23 @@ public class EntityRule {
private void onActionMove(Context context, EntityMessage message, JSONObject jargs) throws JSONException { private void onActionMove(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
long target = jargs.getLong("target"); long target = jargs.getLong("target");
DB db = DB.getInstance(context);
EntityFolder folder = db.folder().getFolder(target);
if (folder == null)
throw new IllegalArgumentException("Rule move to folder not found");
EntityOperation.queue(context, message, EntityOperation.MOVE, target, false); EntityOperation.queue(context, message, EntityOperation.MOVE, target, false);
} }
private void onActionCopy(Context context, EntityMessage message, JSONObject jargs) throws JSONException { private void onActionCopy(Context context, EntityMessage message, JSONObject jargs) throws JSONException {
long target = jargs.getLong("target"); long target = jargs.getLong("target");
DB db = DB.getInstance(context);
EntityFolder folder = db.folder().getFolder(target);
if (folder == null)
throw new IllegalArgumentException("Rule copy to folder not found");
EntityOperation.queue(context, message, EntityOperation.COPY, target, false); EntityOperation.queue(context, message, EntityOperation.COPY, target, false);
} }

@ -837,15 +837,15 @@ public class FragmentRule extends FragmentBase {
case EntityRule.TYPE_MOVE: case EntityRule.TYPE_MOVE:
case EntityRule.TYPE_COPY: case EntityRule.TYPE_COPY:
EntityFolder target = (EntityFolder) spTarget.getSelectedItem(); EntityFolder target = (EntityFolder) spTarget.getSelectedItem();
jaction.put("target", target.id); jaction.put("target", target == null ? -1 : target.id);
break; break;
case EntityRule.TYPE_ANSWER: case EntityRule.TYPE_ANSWER:
EntityIdentity identity = (EntityIdentity) spIdent.getSelectedItem(); EntityIdentity identity = (EntityIdentity) spIdent.getSelectedItem();
EntityAnswer answer = (EntityAnswer) spAnswer.getSelectedItem(); EntityAnswer answer = (EntityAnswer) spAnswer.getSelectedItem();
boolean cc = cbCc.isChecked(); boolean cc = cbCc.isChecked();
jaction.put("identity", identity.id); jaction.put("identity", identity == null ? -1 : identity.id);
jaction.put("answer", answer.id); jaction.put("answer", answer == null ? -1 : answer.id);
jaction.put("cc", cc); jaction.put("cc", cc);
break; break;
} }

Loading…
Cancel
Save