Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4488477

LOGGING APIs: XMLFormatter.format(LogRecord) throws NPE

XMLWordPrintable

    • beta3
    • generic
    • generic
    • Verified



      Name: elR10090 Date: 08/06/2001



      The following test shows that the XMLFormatter.format(LogRecord) method throws
      undocumented NullPointerException for a record created with the
      LogRecord(Level, String) constructor if the source logger name for the record
      is null.

      The method throws NPE in the last implementation (Merlin-b74), but works
      correctly in the Merlin-b73.

      import java.util.logging.*;
      import java.io.*;

      public class Test {
          final static LogManager logManager = LogManager.getLogManager();
          final static XMLFormatter formatter = new XMLFormatter();
          final static LogRecord record
              = new LogRecord(Level.INFO, "Message to XMLFormatter");

          public static void main (String args[]) {
              System.exit(95 + run(args, System.out));
          }

          public static int run(String args[], PrintStream out) {
              try {
                  String s = formatter.format(record);
                  out.println("# Formatted message is: ");
                  out.println(s);
              } catch (NullPointerException e) {
                  out.println("# Unexpected exception.");
                  e.printStackTrace(out);
              }
              
              return 0;
          }
      }

      % .../jdk1.4.0beta-b74/solsparc/bin/java Test
      # Unexpected exception.
      java.lang.NullPointerException
              at java.util.logging.XMLFormatter.escape(XMLFormatter.java:61)
              at java.util.logging.XMLFormatter.format(XMLFormatter.java:97)
              at Test.run(Test.java:16)
              at Test.main(Test.java:11)
              
      % .../jdk1.4.0beta-b73/solsparc/bin/java Test
      # Formatted message is:
      <record>
        <date>2001-08-06T13:26:23</date>
        <millis>997082783779</millis>
        <sequence>0</sequence>
        <logger>null</logger>
        <level>INFO</level>
        <thread>10</thread>
        <message>Message to XMLFormatter</message>
      </record>

      This bug affects the following tests from tesbase_nsk:

          nsk/logging/FileHandler/publish/publish002
          nsk/logging/Formatter/Formatter/formatter001
          nsk/logging/LogRecord/setSequenceNumber/setsequencenmb003
          nsk/logging/LogRecord/setThreadID/setthreadid003
          nsk/logging/SocketHandler/publish/publish002
          nsk/logging/XMLFormatter/format/format001
          nsk/logging/XMLFormatter/format/format002
          nsk/logging/XMLFormatter/format/format003

      ======================================================================

            ghamiltosunw Graham Hamilton (Inactive)
            latkinsunw Latkin Latkin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: