-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta
-
generic
-
generic
-
Verified
Name: elR10090 Date: 10/13/2000
The convenience method Formatter.formatMessage(LogRecord) doesn't
return localized message if formatting fails by any reason.
It returns key that looks like it's not found in the ResourceBundle.
Log and test source follow.
formatmsg002.log:
# Wrong message "3", expected "three: {0,number}"
# TEST FAILED.
formatmsg002.java source:
// File: @(#)formatmsg002.java 1.1 00/10/13
// Copyright 10/13/00 Sun Microsystems, Inc. All Rights Reserved
package logging.Formatter.formatMessage;
import java.util.logging.*;
import java.text.*;
import java.util.*;
import java.io.*;
public class formatmsg002 {
final static int PASSED = 0;
final static int FAILED = 2;
final static int JCK_STATUS_BASE = 95;
final static String failMessage = "# TEST FAILED.";
final static String testMessage = "Touchstone message";
final static String testBundleName = TestBundle.class.getName();
final static ResourceBundle bundle =
ResourceBundle.getBundle(testBundleName);
final static Object emptyParams[] = {};
final static Object testParams[] = { "Oups!", new Integer(1), null };
final static LogRecord records[] = {
new LogRecord(Level.INFO, "0"),
new LogRecord(Level.INFO, "1"),
new LogRecord(Level.INFO, "2"),
new LogRecord(Level.INFO, "3")
};
private static Formatter formatter = new TestFormatter();
private static boolean testFailed = false;
private static boolean verbose = false;
public static int run(String args[], PrintStream out) {
verbose = (args.length > 0) && args[0].equals("-v");
/* Exercise the following records:
*
* [0] contains zero length array of parameters
* [1] message string doesn't contain "{0"
* [2] message string contains extra argument
* [3] contains array with an argument that is not
* of the right class for the specified format
*/
for (int i = 0; i < records.length; i++) {
LogRecord r = records[i];
r.setParameters(i > 0 ? testParams : emptyParams);
r.setResourceBundleName(testBundleName);
r.setResourceBundle(bundle);
String master = bundle.getString("" + i);
try {
master = MessageFormat.format(master, r.getParameters());
} catch (Exception ex) {
if (verbose) {
out.println(ex);
}
}
String message = formatter.formatMessage(r);
if (!message.equals(master)) {
out.println("# Wrong message \"" + message
+ "\", expected \"" + master + "\"");
testFailed = true;
}
if (verbose) {
out.println("Exp: " + master + "\nGot: " + message);
}
}
if (testFailed) {
out.println(failMessage);
return FAILED;
} else {
return PASSED;
}
}
static class TestFormatter extends Formatter {
// This method is never used in the test
public String format (LogRecord record) {
return null;
}
}
public static class TestBundle extends ListResourceBundle {
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
{ "0", "zero: {0}" },
{ "1", "one: plain" },
{ "2", "two: {0}, {1}, {2}" },
{ "3", "three: {0,number}" }
};
}
public static void main(String args[]) {
// produce JCK-like exit status.
System.exit(run(args, System.out) + JCK_STATUS_BASE);
}
}
======================================================================
Name: elR10090 Date: 02/01/2001
This bug affects the following testbase_nsk test:
nsk/logging/Formatter/formatMessage/formatmsg002
======================================================================