JDK-4375457 : LOGGING APIs: LogManager fails loggers hierarchy for empty names
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.logging
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Future Project
  • OS: generic
  • CPU: generic
  • Submitted: 2000-10-02
  • Updated: 2024-04-12
  • Resolved: 2005-05-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Relates :  
Description

Name: elR10090			Date: 10/02/2000



Logging APIs specification (draft 0.49) states:

"setLevel(String, Level)

... (skipped)

The given log level applies to the named Logger (if it exists), and
on any other named Loggers below that name in the naming hierarchy."

and

"The namespace should typically be aligned with the Java packaging
namespace, but is not required to follow it slavishly."

If any "not follow it slavishly" and define some loggers with
exotic names like ".something" or "something..else" with the
empty parts between dots, then the LogManager will not properly
build its loggers tree as the following test shows.

IMHO, the usage of empty parts of a logger names should be straightly
restricted in the spec and accordingly implemented. Unless to the contrary
it should be straightly permitted in spec and the LogManager namespace
algorithm should be fixed.

setlevel003 log:

# Wrong logger "a..b.c" level "1", expected "2"
# TEST FAILED.

setlevel003.java source:

// File: @(#)setlevel003.java   1.1 00/10/02
// Copyright 10/02/00 Sun Microsystems, Inc.  All Rights Reserved

package logging.LogManager.setLevel;

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

public class setlevel003 {

    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 names[] = {
        "",
        "a",
        "a..b",
        "a..b.c"
    };

    private static boolean testFailed = false;
    private static boolean verbose = false;
    private static Vector loggers = new Vector();

    public static int run(String args[], PrintStream out) {
        verbose = (args.length > 0) && args[0].equals("-v");

        LogManager manager = LogManager.getLogManager();

        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            try {
                loggers.addElement(Logger.getLogger(name));
                if (verbose) {
                    out.println(
                        "logger \"" + name + "\" was successfully added");
                }
            } catch (IllegalArgumentException ex) {
                if (verbose) {
                    out.println(
                        "getLogger: logger \"" + name + "\" has illegal name");
                }
            }
        }

        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            Level level = Level.parse("" + i);
            try {
                manager.setLevel(name, level);
                if (verbose) {
                    out.println("Level " + level + " logger " + name);
                }
            } catch (IllegalArgumentException ex) {
                if (verbose) {
                    out.println(
                        "setLevel: logger \"" + name + "\" has illegal name");
                }
                continue;
            }
            for (int j = i; j < names.length; j++) {
                String subName = names[j];
                Level subLevel = manager.getLevel(subName);
                if (!level.equals(subLevel)) {
                    out.println("# Wrong logger \"" + subName
                        + "\" level \"" + subLevel
                        + "\", expected \"" + level + "\"");
                    testFailed = true;
                }
            }
        }

        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: 02/01/2001


This bug affects the following testbase_nsk test:
    nsk/logging/LogManager/setLevel/setlevel003


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

Comments
EVALUATION Thanks for the report. My intention was that LogManager would allow empty names. However several errors prevented this: Both of the Logger.getLogger methods incorrectly rejected the empty name "", which should in fact be the root of the tree. The LogManager.findNode and LogManager.getLevel methods were incorrectly checking for the "." character using String.indexOf(".") and then checking if the result was > 0, when they should have been checking the result was >= 0. I have fixed these errors, and now the test program passes correctly. Thanks, - Graham graham.hamilton@Eng 2000-11-05 OK, In code reviewing this with Josh he raised a number of good questions and advised reconsidering whether we should support empty names. So I am going to back this off to evaluated while I think about it some more. graham.hamilton@Eng 2000-11-06
06-11-2000