-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
tiger
-
generic
-
generic
-
Verified
Name: elR10090 Date: 07/16/2001
The current specification (from Merlin-b70) for SocketHandler(String, int) constructor
public SocketHandler(String host, int port) throws IOException
Construct a SocketHandler using a specified host and port. The SocketHandler
is configured based on LogManager properties (or their default values) except
that the given target host and port arguments are used.
Parameters: host - target host.
port - target port.
Throws: IllegalArgumentException - if the host or port are invalid.
IOException - if we are unable to connect to the target host and port.
says that IllegalArgumentException would be thrown if the host is invalid.
The situation if host is empty String is not specified anywhere. Empty String does not define
any particular host name. Maybe "" has some special meaning, for example localhost, but it is
not specified. My understanding is that "" is invalid value for host, so IllegalArgumentException
should be thrown or that case should be specified explicitly.
Please, note, that the constructor throws IllegalArgumentException if host name is null.
See the bug
4398380 Logging APIs: SocketHandler constructors spec need clarification
The following test shows that SocketHandler is created with empty host name.
import java.util.logging.*;
import java.io.*;
import java.net.*;
public class Test {
final static int PORT = 7777;
final static LogManager logManager = LogManager.getLogManager();
static SocketListener listener;
public static void main (String args[]) {
System.exit(95 + run(args, System.out));
}
public static int run(String args[], PrintStream out) {
// Get SocketListener
try {
listener = new SocketListener(PORT);
} catch (Exception e) {
out.println("# TEST FAILED.");
out.println("# Cannot get SocketListener");
e.printStackTrace(out);
return 2;
}
try {
SocketHandler handler = new SocketHandler("", PORT);
out.println("# Handler is " + handler);
return 0;
} catch (IOException e) {
out.println("# IOException is thrown.");
return 2;
} catch (IllegalArgumentException e) {
out.println("# IllegalArgumentException is thrown.");
return 2;
}
}
// SocketListener class
static class SocketListener extends Thread {
private static ServerSocket serverSocket;
public SocketListener(int port) throws IOException {
serverSocket = new ServerSocket(port);
this.start();
}
public void run() {
try {
Socket socket = serverSocket.accept();
} catch (Exception e) {
}
}
}
}
This test outputs:
# Handler is java.util.logging.SocketHandler@4f1d0d
======================================================================
- relates to
-
JDK-4398380 Logging APIs: SocketHandler constructors spec need clarification
-
- Closed
-