-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0, 1.4.2, 5.0
-
tiger
-
generic, x86, sparc
-
generic, linux, solaris, solaris_7, solaris_8, windows_nt
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2165321 | 1.4-pool | Kevin Walls | P4 | Closed | Won't Fix |
Name: elR10090 Date: 08/01/2001
The following is the paragraph that talks about NullPointerException
in logging methods and constructors (java/util/logging/package-summary.html
file in javadoc):
"Null Pointers
In general, unless otherwise noted in the javadoc, methods and contructors
will throw NullPointerException if passed a null argument. The one broad
exception to this rule is that the logging convenience methods in the
Logger class (the log, logp, log, severe, warning, config, fine, finer,
and finest methods) will accept null values for all arguments except for
the initial Level argument (if any)."
There are few methods that do not follow this rule.
1. XMLFormatter.getTail(Handler) also getHead(Handler)
The following test shows that XMLFormatter.getTail(null) does not throw
NullPointerException.
import java.util.logging.*;
import java.io.*;
public class gettail003 {
final static LogManager logManager = LogManager.getLogManager();
final static XMLFormatter formatter = new XMLFormatter();
public static void main (String args[]) {
System.exit(95 + run(args, System.out));
}
public static int run(String args[], PrintStream out) {
try {
String tail = formatter.getTail(null);
out.println("# TEST FAILED.");
out.println("# Tail is \"" + tail + "\", but NullPointerException expected.");
return 2;
} catch (NullPointerException e) {
return 0;
}
}
}
The test outputs
## TEST FAILED.
## Tail is "</log>
#", but NullPointerException expected.
2. tracked as 4625722
3. LogManager.addPropertyChangeListener(PropertyChangeListener),
LogManager.removePropertyChangeListener(PropertyChangeListener)
The method LogManager.addPropertyChangeListener silently returns if
PropertyChangeListener is null. However, the following test shows that
LogManager.readConfiguration() throws unspecified NullPointerException
if null listener is added. So, I believe the method should reject addition
of null listener.
import java.util.logging.*;
import java.io.*;
public class addpcl003 {
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) {
logManager.addPropertyChangeListener(null);
try {
logManager.readConfiguration();
} catch (IOException e) {
out.println("# Cannot read configuration.");
e.printStackTrace(out);
} catch (NullPointerException e) {
out.println("# Cannot read configuration.");
e.printStackTrace(out);
}
return 0;
}
}
The test outputs:
# Cannot read configuration.
java.lang.NullPointerException
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:255)
at java.util.logging.LogManager.readConfiguration(LogManager.java:613)
at java.util.logging.LogManager.readConfiguration(LogManager.java:520)
at Test.run(Test.java:14)
at Test.main(Test.java:8)
Since null listener should not be added, LogManager.removePropertyChangeListener(null)
should also throw the exception.
4. There are few methods that have unclear specification about NullPointerException.
a) removeHandler methods:
Logger.removeHandler(Handler)
On the one hand, according to the paragraph about "Null Pointers", both
methods shoud throw NPE. On the other, according to the
Logger.removeHandler(Handler) spec (for example)
public void removeHandler(Handler handler) throws SecurityException
Remove a log Handler.
Returns silently if the given Handler is not found.
Parameters: handler - a logging Handler
Throws: SecurityException - if a security manager exists and if the
caller does not have LoggingPermission("control").
null Handler could be interpreted as "not found Handler" and the method
should not throw any exception.
The following implementation does not throw NPE for both methods.
b) see 4653375
5. see 4648829
This bug affects the following tests from tesbase_nsk:
nsk/logging/XMLFormatter/getTail/gettail003
nsk/logging/Level/Level/level004
nsk/logging/LogManager/addPropertyChangeListener/addpcl003
nsk/logging/LogManager/removePropertyChangeListener/rmpcl003
nsk/logging/LogManager/removeGlobalHandler/rmglh003
All tests will appear in the next release r06 of testbase_nsk
testbase located at:
/net/sqesvr.eng/export/vsn/VM/testbase/testbase_nsk.v14
======================================================================
Name: elR10090 Date: 08/06/2001
Alexey Gibadullin, ###@###.###
Three more methods should be included to the item 4.
4. c) The method LogManager.getLogger(String) also has unclear
specification about NullPointerException:
public Logger getLogger(String name)
Method to find a named logger.
Note that since untrusted code may create loggers with arbitrary
names this method should not be relied on to find Loggers for
security sensitive logging.
Parameters: name - name of the logger
Returns: matching logger or null if none is found
On the one hand, the method can throw NPE if logger name is null
(according to the "Null Pointers" paragraph). But on the other,
a logger with null name may not be found and the method can
return null without throwing an exception.
4. d) The methods Logger.getAnonymousLogger(resourceBundleName) and
Logger.getLogger(name, resourceBundleName) do not specify any
behavior for the case when resourceBundleName argument is null.
The Logger(String, String) constructor says that resourceBundleName
may be null (if none of the messages require localization) explicitly.
It seems that both methods Logger.getAnonymousLogger(String) and
Logger.getLogger(String, String) should have the same statement.
======================================================================
Name: elR10090 Date: 09/13/2001
Alexey Gibadullin, ###@###.###
This bug also affects the following test from testbase_nsk:
nsk/logging/Level/Level_sis/levelsis005
======================================================================
nsk/logging/LogManager/addPropertyChangeListener/addpcl003
nsk/logging/LogManager/removePropertyChangeListener/rmpcl003
- backported by
-
JDK-2165321 LOGGING APIs: Expected NullPointerException isn't thrown
-
- Closed
-
- duplicates
-
JDK-4495763 nsk/logging/Level/Level_sis/levelsis005 test fails.
-
- Closed
-
-
JDK-4776634 java.util.logging.Formatter.get[Head|Tail]: no NPE
-
- Closed
-
- relates to
-
JDK-4478366 logging: logging classes should specify what happens on null args
-
- Closed
-
-
JDK-4486791 LOGGING APIs: Undetermined behavior on empty logger names
-
- Resolved
-