From 16c8a19be8ae510529e41112d813d91fec2cd77a Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Tue, 7 May 2013 13:09:03 +0000
Subject: [PATCH]  * Streaming: Throw chained IOE from streams to get correct
 location

---
 .../java/src/net/i2p/client/streaming/Connection.java  | 10 ++++++----
 .../net/i2p/client/streaming/MessageInputStream.java   |  9 ++++++---
 .../net/i2p/client/streaming/MessageOutputStream.java  |  9 ++++++---
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/apps/streaming/java/src/net/i2p/client/streaming/Connection.java b/apps/streaming/java/src/net/i2p/client/streaming/Connection.java
index 5112600e8d..dce484500c 100644
--- a/apps/streaming/java/src/net/i2p/client/streaming/Connection.java
+++ b/apps/streaming/java/src/net/i2p/client/streaming/Connection.java
@@ -542,8 +542,9 @@ class Connection {
             _context.simpleScheduler().addEvent(new DisconnectEvent(), DISCONNECT_TIMEOUT);
         }
         _resetReceived = true;
-        _outputStream.streamErrorOccurred(new IOException("Reset received"));
-        _inputStream.streamErrorOccurred(new IOException("Reset received"));
+        IOException ioe = new IOException("Reset received");
+        _outputStream.streamErrorOccurred(ioe);
+        _inputStream.streamErrorOccurred(ioe);
         _connectionError = "Connection reset";
         synchronized (_connectLock) { _connectLock.notifyAll(); }
     }
@@ -998,8 +999,9 @@ class Connection {
                         _log.debug(buf.toString());
                     }
                     
-                    _inputStream.streamErrorOccurred(new IOException("Inactivity timeout"));
-                    _outputStream.streamErrorOccurred(new IOException("Inactivity timeout"));
+                    IOException ioe = new IOException("Inactivity timeout");
+                    _inputStream.streamErrorOccurred(ioe);
+                    _outputStream.streamErrorOccurred(ioe);
                     // Clean disconnect if we have already scheduled one
                     // (generally because we already sent a close)
                     disconnect(_disconnectScheduledOn >= 0);
diff --git a/apps/streaming/java/src/net/i2p/client/streaming/MessageInputStream.java b/apps/streaming/java/src/net/i2p/client/streaming/MessageInputStream.java
index eb168d1106..5767ec034e 100644
--- a/apps/streaming/java/src/net/i2p/client/streaming/MessageInputStream.java
+++ b/apps/streaming/java/src/net/i2p/client/streaming/MessageInputStream.java
@@ -465,10 +465,13 @@ class MessageInputStream extends InputStream {
     }
     
     private void throwAnyError() throws IOException {
-        if (_streamError != null) {
-            IOException ioe = _streamError;
+        IOException ioe = _streamError;
+        if (ioe != null) {
             _streamError = null;
-            throw ioe;
+            // constructor with cause not until Java 6
+            IOException ioe2 = new IOException("Input stream error");
+            ioe2.initCause(ioe);
+            throw ioe2;
         }
     }
 }
diff --git a/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java b/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java
index 4f7682dc91..db317eab88 100644
--- a/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java
+++ b/apps/streaming/java/src/net/i2p/client/streaming/MessageOutputStream.java
@@ -446,10 +446,13 @@ class MessageOutputStream extends OutputStream {
     public boolean getClosed() { return _closed; }
     
     private void throwAnyError() throws IOException {
-        if (_streamError != null) {
-            IOException ioe = _streamError;
+        IOException ioe = _streamError;
+        if (ioe != null) {
             _streamError = null;
-            throw ioe;
+            // constructor with cause not until Java 6
+            IOException ioe2 = new IOException("Output stream error");
+            ioe2.initCause(ioe);
+            throw ioe2;
         }
     }
     
-- 
GitLab