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

Logger.getLogger(name, null) should not allow to reset a non-null resource bundle

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 8
    • core-libs
    • None
    • 8
    • b106
    • Verified

    Description

      Below shows the test case that passes with JDK 7 but fails with JDK8.

      If a logger of a given name exists, Logger.getLogger(name, null) throws IAE when running with JDK 7. Looks like this is related to the fix for JDK-7045594 in JDK 8 [1].

      [1] http://hg.openjdk.java.net/jdk8/tl/jdk/rev/4a221501079a

      ----------------------------------------------------------------
      import java.util.logging.*;
      import java.util.*;

      public class TestLogger {

          public static final String RESOURCE_BUNDLE = "myresource";
          public static final String FOO_LOGGER = "org.foo.Foo";
          public static final String BAR_LOGGER = "org.bar.Bar";
          public static final String GEE_LOGGER = "org.gee.Gee";

          public static void main(String[] args) {
              newLogger(FOO_LOGGER, RESOURCE_BUNDLE);
              newLogger(FOO_LOGGER);
              newLogger(BAR_LOGGER);
              newLogger(BAR_LOGGER, RESOURCE_BUNDLE);
              newLogger(GEE_LOGGER, null);
              newLogger(GEE_LOGGER, RESOURCE_BUNDLE);
              try {
                  Logger.getLogger(GEE_LOGGER, null);
                  throw new RuntimeException("Shouldn't allow to reset the resource bundle");
              } catch (IllegalArgumentException e) {}
          }

          private static List<Logger> strongRefs = new ArrayList<>();
          private static void newLogger(String name) {
              strongRefs.add(Logger.getLogger(name));
          }
          private static void newLogger(String name, String resourceBundleName) {
              strongRefs.add(Logger.getLogger(name, resourceBundleName));
          }
      }

      Attachments

        Issue Links

          Activity

            People

              dfuchs Daniel Fuchs
              mchung Mandy Chung
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: