mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8282686: Add constructors taking a cause to SocketException
Reviewed-by: alanb, xuelei, lancea, dfuchs
This commit is contained in:
parent
7194097bca
commit
1faa5c8092
7 changed files with 90 additions and 25 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -1353,9 +1353,7 @@ public class DatagramSocket implements java.io.Closeable {
|
|||
Throwable cause = e.getCause();
|
||||
if (cause instanceof SocketException)
|
||||
return (SocketException) cause;
|
||||
SocketException se = new SocketException(e.getMessage());
|
||||
se.initCause(e);
|
||||
return se;
|
||||
return new SocketException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -52,4 +52,27 @@ public class SocketException extends IOException {
|
|||
*/
|
||||
public SocketException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code SocketException} with the
|
||||
* specified detail message and cause.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
* @param cause the cause
|
||||
* @since 19
|
||||
*/
|
||||
public SocketException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@code SocketException} with the
|
||||
* specified cause.
|
||||
*
|
||||
* @param cause the cause
|
||||
* @since 19
|
||||
*/
|
||||
public SocketException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -120,12 +120,8 @@ public abstract class SocketFactory
|
|||
// The Exception is used by HttpsClient to signal that
|
||||
// unconnected sockets have not been implemented.
|
||||
//
|
||||
UnsupportedOperationException uop = new
|
||||
UnsupportedOperationException();
|
||||
SocketException se = new SocketException(
|
||||
"Unconnected sockets not implemented");
|
||||
se.initCause(uop);
|
||||
throw se;
|
||||
throw new SocketException("Unconnected sockets not implemented",
|
||||
new UnsupportedOperationException());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -173,8 +173,7 @@ class DefaultSSLServerSocketFactory extends SSLServerSocketFactory {
|
|||
}
|
||||
|
||||
private ServerSocket throwException() throws SocketException {
|
||||
throw (SocketException)
|
||||
new SocketException(reason.toString()).initCause(reason);
|
||||
throw new SocketException(reason.toString(), reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -263,8 +263,7 @@ class DefaultSSLSocketFactory extends SSLSocketFactory
|
|||
}
|
||||
|
||||
private Socket throwException() throws SocketException {
|
||||
throw (SocketException)
|
||||
new SocketException(reason.toString()).initCause(reason);
|
||||
throw new SocketException(reason.toString(), reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -219,9 +219,7 @@ public class DatagramSocketAdaptor
|
|||
} catch (AlreadyConnectedException e) {
|
||||
throw new IllegalArgumentException("Connected and packet address differ");
|
||||
} catch (ClosedChannelException e) {
|
||||
var exc = new SocketException("Socket closed");
|
||||
exc.initCause(e);
|
||||
throw exc;
|
||||
throw new SocketException("Socket closed", e);
|
||||
}
|
||||
} finally {
|
||||
if (bb != null) {
|
||||
|
@ -249,9 +247,7 @@ public class DatagramSocketAdaptor
|
|||
p.setSocketAddress(sender);
|
||||
}
|
||||
} catch (ClosedChannelException e) {
|
||||
var exc = new SocketException("Socket closed");
|
||||
exc.initCause(e);
|
||||
throw exc;
|
||||
throw new SocketException("Socket closed", e);
|
||||
} finally {
|
||||
Util.offerFirstTemporaryDirectBuffer(bb);
|
||||
}
|
||||
|
@ -481,7 +477,7 @@ public class DatagramSocketAdaptor
|
|||
joinGroup(new InetSocketAddress(group, 0), null);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// 1-arg joinGroup does not specify IllegalArgumentException
|
||||
throw (SocketException) new SocketException("joinGroup failed").initCause(iae);
|
||||
throw new SocketException("joinGroup failed", iae);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -493,7 +489,7 @@ public class DatagramSocketAdaptor
|
|||
leaveGroup(new InetSocketAddress(group, 0), null);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// 1-arg leaveGroup does not specify IllegalArgumentException
|
||||
throw (SocketException) new SocketException("leaveGroup failed").initCause(iae);
|
||||
throw new SocketException("leaveGroup failed", iae);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue