-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
beta
-
generic
-
generic
-
Verified
Name: elR10090 Date: 09/01/2000
There is a citation from the Java Logging APIs specification:
| parse(String)
|
| ... (skiped)
|
| Throws: IllegalArgumentException - if the value is neither one of the
| known names nor an integer.
while in the reality if the parameter is null, method throws
NullPointerException.
IMHO, it must throws IllegalArgumentException as we have in specification.
Log and source follows:
parse001 log:
# Unexpected exception java.lang.NullPointerException while parsing "null"
# TEST FAILED.
parse001.java source:
// File: %W% %E%
// Copyright %G% Sun Microsystems, Inc. All Rights Reserved
package logging.Level.parse;
import java.util.logging.*;
import java.io.*;
public class parse001 {
final static int PASSED = 0;
final static int FAILED = 2;
final static int JCK_STATUS_BASE = 95;
final static String failMessage = "# TEST FAILED.";
private static boolean testFailed = false;
private static PrintStream sout;
private static Level level;
private static void checkThrow(String name) {
try {
level = Level.parse(name);
sout.println("# IllegalArgumentException exception was not thrown"
+ " while parsing \"" + name + "\"");
testFailed = true;
} catch (IllegalArgumentException ex) {
// ok
} catch (Exception ex) {
sout.println("# Unexpected exception " + ex
+ " while parsing \"" + name + "\"");
testFailed = true;
}
}
public static int run(String args[], PrintStream out) {
sout = out;
Level levels[] = {
Level.ALL, Level.FINEST, Level.FINER,
Level.FINE, Level.CONFIG, Level.INFO,
Level.WARNING, Level.SEVERE, Level.OFF
};
// parse standard logging levels by name
for (int i = 0; i < levels.length; i++) {
try {
level = Level.parse(levels[i].toString());
} catch (Exception ex) {
out.println("# Unexpected exception " + ex
+ " while parsing " + levels[i]);
testFailed = true;
continue;
}
if (!level.equals(levels[i])) {
out.println("# Unexpected level " + level
+ " while parsing " + levels[i]);
testFailed = true;
}
}
// parse standard logging levels by value
for (int i = 0; i < levels.length; i++) {
try {
level = Level.parse("" + levels[i].intValue());
} catch (Exception ex) {
out.println("# Unexpected exception " + ex
+ " while parsing " + levels[i]);
testFailed = true;
continue;
}
if (!level.equals(levels[i])) {
out.println("# Unexpected level " + level
+ " while parsing " + levels[i].intValue());
testFailed = true;
}
}
// check throwing Exception
checkThrow(null);
checkThrow("abracadabra");
if (testFailed) {
out.println(failMessage);
return FAILED;
} else {
return PASSED;
}
}
public static void main(String args[]) {
// produce JCK-like exit status.
System.exit(run(args, System.out) + JCK_STATUS_BASE);
}
}
======================================================================
Name: elR10090 Date: 09/07/2000
Possibly, it's implemented as intended and the method must not check that
the argument is null. Then specification needs to be improved so that it
more precisely describes the throwing condition. For instance:
IllegalArgumentException - if the argument is not null and does not
contain one of the known level names or a parsable integer.
NullPointerException - if the argument is null.
In any case, the phrase:
| ... - if the value is neither one of the names nor an integer.
IMHO needs to be clarified:
(1) meaning of the term "value" is not clear;
(2) nothing is said about null;
(3) BTW, the term "names" is not strictly defined in specification.
======================================================================