Summary
Add conventional constructors that take a cause to SocketException to avoid the need to call initCause as part of creating the exception.
Problem
The creation of many SocketExceptions involves setting the cause, but the set of constructors does not include any ones taking a cause.
Solution
Add the two missing conventional constructors that take a cause argument.
Specification
--- a/src/java.base/share/classes/java/net/SocketException.java
+++ b/src/java.base/share/classes/java/net/SocketException.java
@@ -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);
+ }
}
- csr of
-
JDK-8282686 Add constructors taking a cause to SocketException
-
- Resolved
-