mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 23:34:52 +02:00
8299475: Enhance SocketException by cause where it is missing in net and nio area
Reviewed-by: alanb
This commit is contained in:
parent
2ccdefc81c
commit
c929d8be5d
4 changed files with 25 additions and 8 deletions
|
@ -312,7 +312,8 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
|
|||
connectionReset = true;
|
||||
throw new SocketException("Connection reset");
|
||||
} catch (IOException ioe) {
|
||||
throw new SocketException(ioe.getMessage());
|
||||
// throw SocketException to maintain compatibility
|
||||
throw asSocketException(ioe);
|
||||
} finally {
|
||||
endRead(n > 0);
|
||||
}
|
||||
|
@ -410,7 +411,8 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
|
|||
} catch (InterruptedIOException e) {
|
||||
throw e;
|
||||
} catch (IOException ioe) {
|
||||
throw new SocketException(ioe.getMessage());
|
||||
// throw SocketException to maintain compatibility
|
||||
throw asSocketException(ioe);
|
||||
} finally {
|
||||
endWrite(n > 0);
|
||||
}
|
||||
|
@ -1084,7 +1086,7 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
|
|||
} catch (SocketException e) {
|
||||
throw e;
|
||||
} catch (IllegalArgumentException | IOException e) {
|
||||
throw new SocketException(e.getMessage());
|
||||
throw asSocketException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1136,7 +1138,7 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
|
|||
} catch (SocketException e) {
|
||||
throw e;
|
||||
} catch (IllegalArgumentException | IOException e) {
|
||||
throw new SocketException(e.getMessage());
|
||||
throw asSocketException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1249,6 +1251,19 @@ public final class NioSocketImpl extends SocketImpl implements PlatformSocketImp
|
|||
return remainingNanos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SocketException from the given exception.
|
||||
*/
|
||||
private static SocketException asSocketException(Exception e) {
|
||||
if (e instanceof SocketException se) {
|
||||
return se;
|
||||
} else {
|
||||
var se = new SocketException(e.getMessage());
|
||||
se.setStackTrace(e.getStackTrace());
|
||||
return se;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the socket protocol family.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue