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

No documented way to use Logger.global in JDK1.5 that would not be deprecated in JDK1.6

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • core-libs
    • None

      I've just found out that there does not seem to be a way to write:

      Logger.global.warning("watch out");

      in JDK1.5, so it is not deprecated in JDK1.6.


      This forms a slight problem for NetBeans as we just switched to use java.util.logging extensively, and we need to compile on 1.5 as well as 1.6. Right now our code, compiled on 1.6 will throw tons of deprecations and we have no way to prevent them.

      The explanation why Logger.global says that this is due to possible deadlocks, but I belive that there could be another solution that would prevent the deadlocks and kept the field usable. Just create a logger delegate:

      public static Logger global = new GlobalLoggerDelegate();

      class GlobalLoggerDelegate extends Logger {
        private Logger delegate;

        // overrwites all methods to do lazy init first, then the impl

        public void warning(String msg) {
          lazyInit();
          delegate.warning(msg);
        }

        private void lazyInit() {
          if (delegate == null) {
            delegate = getLogger("global");
          }
        }
      }

            Unassigned Unassigned
            jtulach Jaroslav Tulach (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: