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

LogRecord.setResourceBundleName() does not initialize the resource bundle field.

XMLWordPrintable

      While converting some GlassFish code to use localization I ran into an issue with the java.util.logging API.
       
      The use case is early startup log messages are queued in a buffer and then later while the log file is initialized they are written to disk.
       
      See the following snippet of code.
       
              LogRecord lr = new LogRecord(Level.INFO, LogFacade.GF_VERSION_INFO);
              lr.setParameters(new Object[]{ Version.getFullVersion()});
              lr.setResourceBundle(ResourceBundle.getBundle(LogFacade.LOGGING_RB_NAME));
              lr.setThreadID((int) Thread.currentThread().getId());
              lr.setLoggerName(LogFacade.LOGGING_LOGGER_NAME);
              EarlyLogHandler.earlyMessages.add(lr);
       
      The issue is that earlier I was doing lr.setResourceBundleName(LogFacade.LOGGING_RB_NAME);
       
      This resulted in the early messages appearing in the log file with just keys and without localization.
       
      This was not working because the setResourceBundleName setter does not initialize the actual resource bundle used during logging but just initializes a String value.
       
      So the resourceBundleName and the resourceBundle fields in the LogRecord class can go out of sync.
       
      This is problematic from an API standpoint.

            dfuchs Daniel Fuchs
            sanshriv Sandeep Shrivastava
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: