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

inefficiency in java.util.ResourceBundle causes extra network traffic

XMLWordPrintable

    • beta
    • generic, x86
    • generic, windows_nt



      Name: chT40241 Date: 08/24/98


      Found a bug in java.util.ResourceBundle; submitted to JavaSoft

      Consider a call to java.util.ResourceBundle.getBundle("com.sas.Resources")
      where the default locale is en_US
      The only resource bundle that exists
      is com/sas/Resources.properties

      Tracing the network traffic (i.e. look at the Java console when running
      an applet with the Java PlugIn 1.1[.1], you'll see the following network
      reads occurring:

      Opening http://d133.us.sas.com/sasjavasoft/com/sas/Resources_en_US.class no proxy
      Opening http://d133.us.sas.com/sasjavasoft/com/sas/Resources_en_US.properties no proxy
      Opening http://d133.us.sas.com/sasjavasoft/com/sas/Resources_en.class no proxy
      Opening http://d133.us.sas.com/sasjavasoft/com/sas/Resources_en.properties no proxy
      Opening http://d133.us.sas.com/sasjavasoft/com/sas/Resources_en_US.class no proxy
      Opening http://d133.us.sas.com/sasjavasoft/com/sas/Resources_en_US.properties no proxy
      Opening http://d133.us.sas.com/sasjavasoft/com/sas/Resources_en.class no proxy
      Opening http://d133.us.sas.com/sasjavasoft/com/sas/Resources_en.properties no proxy
      Opening http://d133.us.sas.com/sasjavasoft/com/sas/Resources.class no proxy

      that is, there are two attempted network reads each of

        com/sas/Resources_en_US.class
        com/sas/Resources_en_US.properties
        com/sas/Resources_en.class
        com/sas/Resources_en.properties

      when there should only be one each.

      Inspecting the JDK 1.1.6 code for ResourceBundle shows why.

      ResourceBundle.getBundle(String baseName) calls
          getBundle(baseName,Locale.getDefault(),getLoader())
      which calls
          findBundle(baseName,Locale.getDefault(),getLoader(),false)
      and if that fails, turns around and calls
          findBundle(baseName,Locale.getDefault(),getLoader(),true)

      findBundle(...,false) tries to find the resource (i.e. com.sas.Resources)
      via the passed in Locale "en_US" and "en", and fails, then
      findBundle(...,true) tries to find the resource (i.e. com.sas.Resources)
      via the passed in Locale "en_US" and "en", and then finally
      by no locale, and finally finds it.

      Further, findBundle(...,false) does *not* mark com.sas.Resources_en_US and
      com.sas.Resources_en as NOTFOUND,
      so in the call to findBundle(...,true) it retries
      com.sas.Resources_en_US and com.sas.Resources_en again (and fails)
      and only when it finds com/sas/Resources.properties does it
      mark com.sas.Resources_en_US and com.sas.Resources_en as NOTFOUND.

      This causes much unecessary network traffic when loading resource
      bundles, especially when the default resource bundle matches
      the en_US locale, but there is no corresponding en_US .properties file.

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

            duke J. Duke
            chickeysunw Chuck Hickey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: