summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Zhihai Xu <zhihaixu@google.com> 2014-01-04 00:54:02 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2014-01-04 00:54:02 +0000
commit2208e652d6881bb8747cb50d87d98a679d7c0e07 (patch)
treed6ba171b0fa0d28b69c564ed28c975729097d27c
parentd218a92c0afb8c0d98135b20b52ac87236e1c935 (diff)
parent610770d7129a33fdca5c23939f9ee0a80d0322f9 (diff)
Merge "NPE in BluetoothSocket.write()"
-rw-r--r--core/java/android/bluetooth/BluetoothSocket.java27
1 files changed, 14 insertions, 13 deletions
diff --git a/core/java/android/bluetooth/BluetoothSocket.java b/core/java/android/bluetooth/BluetoothSocket.java
index ddefc70dfd47..22322e338ea7 100644
--- a/core/java/android/bluetooth/BluetoothSocket.java
+++ b/core/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