From ad96cd3f5f8c07ad6569cbb4863c782ba0920d3d Mon Sep 17 00:00:00 2001 From: Nick Hudson Date: Tue, 13 Jan 2015 12:02:06 +0000 Subject: Don't call wakeup on closed selectors This operation should be valid according to Javadocs, but triggers a crash on Android Lollipop: https://code.google.com/p/android/issues/detail?id=80785 This workaround avoids the crash, and should not affect behaviour for all other versions. Test-information: Forced disconnect on Lollipop, didn't see crash. Tested MLC with deliberately dropped connections; seems to work as expected. Change-Id: Ia08476266dd92c40bea04076b3c3d8750737c309 Reviewer: Nick Hudson diff --git a/src/com/isode/stroke/network/JavaConnection.java b/src/com/isode/stroke/network/JavaConnection.java index 46f43ab..f1d72bb 100644 --- a/src/com/isode/stroke/network/JavaConnection.java +++ b/src/com/isode/stroke/network/JavaConnection.java @@ -3,7 +3,7 @@ * All rights reserved. */ /* - * Copyright (c) 2010-2013, Isode Limited, London, England. + * Copyright (c) 2010-2015, Isode Limited, London, England. * All rights reserved. */ package com.isode.stroke.network; @@ -340,7 +340,9 @@ public class JavaConnection extends Connection implements EventOwner { @Override public void disconnect() { disconnecting_ = true; - if (selector_ != null) { + // Check "isOpen" to Avoid Android crash see + // https://code.google.com/p/android/issues/detail?id=80785 + if (selector_ != null && selector_.isOpen()) { selector_.wakeup(); } } @@ -348,7 +350,9 @@ public class JavaConnection extends Connection implements EventOwner { @Override public void write(ByteArray data) { worker_.writeBuffer_.add(data.getData()); - if (selector_ != null) { + // Check "isOpen" to Avoid Android crash see + // https://code.google.com/p/android/issues/detail?id=80785 + if (selector_ != null && selector_.isOpen()) { selector_.wakeup(); } -- cgit v0.10.2-6-g49f6