-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
1.4
-
generic
-
generic
Name: elR10090 Date: 08/01/2001
The current logging specification does not define whether logger can have
empty name or not.
Two methods
Logger.getLogger(String) and
Logger.getLogger(String, String)
throw undocumented IllegalArgumentException if logger name is empty. However,
the constructor
Logger(String, String)
does not (see output and test code below).
I believe the costructor should have the same behavior as the methods on empty
logger name and throw IllegalArgumentException too.
import java.util.logging.*;
import java.io.*;
public class Test {
final static LogManager logManager = LogManager.getLogManager();
public static void main (String args[]) {
System.exit(95 + run(args, System.out));
}
public static int run(String args[], PrintStream out) {
try {
Logger logger = Logger.getLogger("");
out.println("Logger created for Logger.getLogger(\"\")");
} catch (IllegalArgumentException e) {
out.println("Unexpected exception for Logger.getLogger(\"\")");
e.printStackTrace(out);
}
try {
Logger logger = Logger.getLogger("", null);
out.println("Logger created for Logger.getLogger(\"\", null)");
} catch (IllegalArgumentException e) {
out.println("Unexpected exception for Logger.getLogger(\"\", null)");
e.printStackTrace(out);
}
Logger logger = new MyLogger("", null);
out.println("Logger created for Logger(\"\", null)");
return 0;
}
static class MyLogger extends Logger {
protected MyLogger(String name, String resourceBoundleName) {
super(name, resourceBoundleName);
}
}
}
The test outputs:
Unexpected exception for Logger.getLogger("")
java.lang.IllegalArgumentException: need a logger name
at java.util.logging.Logger.getLogger(Logger.java:194)
at Test1.run(Test1.java:17)
at Test1.main(Test1.java:12)
Unexpected exception for Logger.getLogger("", null)
java.lang.IllegalArgumentException: need a logger name
at java.util.logging.Logger.getLogger(Logger.java:239)
at Test1.run(Test1.java:25)
at Test1.main(Test1.java:12)
Logger created for Logger("", null)
Please, note, the similar bug
4375457 LOGGING APIs: LogManager fails loggers hierarchy for empty names
is still not closed.
Also, the spec for the method Logger.getLogger(String, String) has a typo:
"public static Logger getLogger(String name, String resourceBundleName)
....
Throws: MissingResourceException - if the named ResourceBundle cannot be found.
IllegalArgumentName - if the Logger already exists and uses a different
^^^^^^^^^^^^^^^^^^^
resource bundle name."
It looks like IllegalArgumentException should be documented.
======================================================================
- relates to
-
JDK-4375457 LOGGING APIs: LogManager fails loggers hierarchy for empty names
-
- Closed
-
-
JDK-4486754 LOGGING APIs: Expected NullPointerException isn't thrown
-
- Closed
-