summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothSocket.java
diff options
context:
space:
mode:
authorZhihai Xu <zhihaixu@google.com>2014-01-04 00:54:02 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-01-04 00:54:02 +0000
commit468074b97f40a9160147db9ecf9eb821be7e2275 (patch)
tree425efad73f5cd57c3e9826d6f7c99352fdabd829 /framework/java/android/bluetooth/BluetoothSocket.java
parent2f7544ce3f0c2e0697318e9961c4ced457b71d5f (diff)
parentf4f4b3be361ff067ec055a1096f539c67a49b7c0 (diff)
Merge "NPE in BluetoothSocket.write()"
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothSocket.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothSocket.java27
1 files changed, 14 insertions, 13 deletions
diff --git a/framework/java/android/bluetooth/BluetoothSocket.java b/framework/java/android/bluetooth/BluetoothSocket.java
index ddefc70dfd..22322e338e 100644
--- a/framework/java/android/bluetooth/BluetoothSocket.java
+++ b/framework/java/android/bluetooth/BluetoothSocket.java
@@ -412,27 +412,28 @@ public final class BluetoothSocket implements Closeable {
* if an i/o error occurs.
*/
/*package*/ void flush() throws IOException {
+ if (mSocketOS == null) throw new IOException("flush is called on null OutputStream");
if (VDBG) Log.d(TAG, "flush: " + mSocketOS);
mSocketOS.flush();
}
/*package*/ int read(byte[] b, int offset, int length) throws IOException {
-
- if (VDBG) Log.d(TAG, "read in: " + mSocketIS + " len: " + length);
- int ret = mSocketIS.read(b, offset, length);
- if(ret < 0)
- throw new IOException("bt socket closed, read return: " + ret);
- if (VDBG) Log.d(TAG, "read out: " + mSocketIS + " ret: " + ret);
- return ret;
+ if (mSocketIS == null) throw new IOException("read is called on null InputStream");
+ if (VDBG) Log.d(TAG, "read in: " + mSocketIS + " len: " + length);
+ int ret = mSocketIS.read(b, offset, length);
+ if(ret < 0)
+ throw new IOException("bt socket closed, read return: " + ret);
+ if (VDBG) Log.d(TAG, "read out: " + mSocketIS + " ret: " + ret);
+ return ret;
}
/*package*/ int write(byte[] b, int offset, int length) throws IOException {
-
- if (VDBG) Log.d(TAG, "write: " + mSocketOS + " length: " + length);
- mSocketOS.write(b, offset, length);
- // There is no good way to confirm since the entire process is asynchronous anyway
- if (VDBG) Log.d(TAG, "write out: " + mSocketOS + " length: " + length);
- return length;
+ if (mSocketOS == null) throw new IOException("write is called on null OutputStream");
+ if (VDBG) Log.d(TAG, "write: " + mSocketOS + " length: " + length);
+ mSocketOS.write(b, offset, length);
+ // There is no good way to confirm since the entire process is asynchronous anyway
+ if (VDBG) Log.d(TAG, "write out: " + mSocketOS + " length: " + length);
+ return length;
}
@Override