This discussion is archived
5 Replies Latest reply: Jan 10, 2013 7:58 AM by jtahlborn RSS

java.util.logging.XmlFormmter  bug ?

983542 Newbie
Currently Being Moderated
C:\Users\x>java -version
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)

java.util.logging.XmlFormmter
Line 153:
if ( parameters != null && parameters.length != 0 && record.getMessage().indexOf("{") == -1 ) { ... }

here, should be *!= -1* ?

because with method in java.util.logging.Formatter.formatMessage(LogRecord record) descript record.getMessage() maybe messagetext, and in this method to index params like:
-----
if (format.indexOf("{0") >= 0 || format.indexOf("{1") >=0 ||
format.indexOf("{2") >=0|| format.indexOf("{3") >=0) {
     return java.text.MessageFormat.format(format, parameters);
-----
so , in my option, this is should be a bug.
  • 1. Re: java.util.logging.XmlFormmter  bug ?
    jtahlborn Expert
    Currently Being Moderated
    980539 wrote:
    C:\Users\x>java -version
    java version "1.6.0_12"
    Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
    Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)

    java.util.logging.XmlFormmter
    Line 153:
    if ( parameters != null && parameters.length != 0 && record.getMessage().indexOf("{") == -1 ) { ... }

    here, should be *!= -1* ?

    because with method in java.util.logging.Formatter.formatMessage(LogRecord record) descript record.getMessage() maybe messagetext, and in this method to index params like:
    -----
    if (format.indexOf("{0") >= 0 || format.indexOf("{1") >=0 ||
    format.indexOf("{2") >=0|| format.indexOf("{3") >=0) {
         return java.text.MessageFormat.format(format, parameters);
    -----
    so , in my option, this is should be a bug.
    a bug according to what? basically, if the formatted message includes the parameters as formatted text (i.e. it includes "{" format indicators), then the xml does not include the parameters as separate elements. if the message does not include the parameters as formatted text, then the parameters are embedded in the xml as additional elements. you may disagree with this decision, but the code is working as intended.
  • 2. Re: java.util.logging.XmlFormmter  bug ?
    983542 Newbie
    Currently Being Moderated
    hi jtahlborn ,
    3ks for your reply, but in my option , the origin idea should check if the LogRecord.getMessage is messagetext or not, just when it's true, then to show all parameters in xml node. in this way, we could know where is replaced with parameter, where is placeholder. may be you can't agree with me.


    p.s.
    ----- java.util.logging.ConsoleHandler
    public void close() {
         flush();
    }

    -----
    here close() exist a prolem, perhaps ,when we choose XMLFormatter, tail message will be loose. so, in my option, this close method implement should just like StreamHandler, but do not real close stream.
    -----
    if (writer != null) {
         try {
         if (!doneHeader) {
         writer.write(getFormatter().getHead(this));
              doneHeader = true;
         }
              writer.write(getFormatter().getTail(this));
              writer.flush();
         //writer.close();
         } catch (Exception ex) {
         // We don't want to throw an exception here, but we
         // report the exception to any registered ErrorManager.
         reportError(null, ex, ErrorManager.CLOSE_FAILURE);
         }
         //writer = null;
         //output = null;
         }
    -----

    Edited by: 980539 on 2013-1-9 上午12:15

    Edited by: 980539 on 2013-1-9 上午12:16
  • 3. Re: java.util.logging.XmlFormmter  bug ?
    jtahlborn Expert
    Currently Being Moderated
    980539 wrote:
    hi jtahlborn ,
    3ks for your reply, but in my option , the origin idea should check if the LogRecord.getMessage is messagetext or not, just when it's true, then to show all parameters in xml node. in this way, we could know where is replaced with parameter, where is placeholder. may be you can't agree with me.
    you asked if it was a bug. i'm saying it's not, it's behaving as designed. whether or not that design fits your needs is a separate question. if not, then you should implement your own Formatter.
  • 4. Re: java.util.logging.XmlFormmter  bug ?
    983542 Newbie
    Currently Being Moderated
    Thanks again.

    Chinese saying, "一千个读者有一千个哈姆莱特", One thousand readers have one thousand hamlet, So you may be correct.

    With your option, ConsoleHandler.close() method's implment was a problem or not ?
  • 5. Re: java.util.logging.XmlFormmter  bug ?
    jtahlborn Expert
    Currently Being Moderated
    980539 wrote:
    With your option, ConsoleHandler.close() method's implment was a problem or not ?
    i can't say that i understood your question regarding the ConsoleHandler.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points