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

MissingResourceException when using Jar indexing under some conditions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.3.0
    • tools
    • jar
    • generic, x86
    • generic, windows_nt

      Name: stC104175 Date: 04/28/2000


      java version "1.3.0rc3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)

      I've discovered what I believe is a bug in the new v1.3 Jar indexing feature.
      If a Java resource bundle is accessed via ResourceBundle.getBundle() in an
      indexed Jar a java.util.MissingResourceException is thrown if all of the
      following are true:

        1. The only resource bundle file that is found for the selected locale is a
           default one. Meaning it has no explicit locale component (e.g.
           MyBundle.class or MyBundle.properties).
        2. The referenced resource bundle file is within a Java package.

      Source:
      package jarpkg;

      import java.util.*;

      public class JarIndexBug {
        private static final Class THIS_CLASS = JarIndexBug.class;

        private static final Locale LOCALE_DEFAULT = Locale.getDefault();
        private static final Locale LOCALE_SPANISH = new Locale( "es", "" );

        private static final String PROPERTY_BUNDLE_NAME = "jarpkg.MyPropertyBundle";

        private static final String[] STRING_IDS = {
          "yes.msg", "no.msg", "maybe.msg"
        };

        public static void main( String[] args ) {

          System.out.println( "\n" + THIS_CLASS.getName() + " Tests:" );

          doTest( PROPERTY_BUNDLE_NAME, LOCALE_DEFAULT );
          doTest( PROPERTY_BUNDLE_NAME, LOCALE_SPANISH );
        }

        private static void doTest( String bundleName, Locale locale ) {
          System.out.println( "\n Results: locale=" + locale.getDisplayName()
                            + ", bundleName=" + bundleName );

          ResourceBundle bundle = getBundle( bundleName, locale );

          if (bundle != null) {
            for (int i=0; i < STRING_IDS.length; i++) {
              String stringId = STRING_IDS[i];
              String string = bundle.getString( stringId );

              if (string == null) string = "**** STRING NOT FOUND ****";

              System.out.println( " " + stringId + "=\"" + string + "\"" );
            }
          }
        }

        private static ResourceBundle getBundle( String bundleName, Locale locale ) {
          ResourceBundle bundle = null;

          try {
            bundle = ResourceBundle.getBundle( bundleName, locale );
          }
          catch (MissingResourceException ex) {
            ex.printStackTrace();
          }

          return bundle;
        }
      }


      Resource Bundles:

      jarpkg.MyPropertyBundle.properties:

      yes.msg=yes
      no.msg=no
      maybe.msg=maybe

      jarpkg.MyPropertyBundle_es.properties:

      yes.msg=s?
      no.msg=ning?n


      Output Text:

      jarpkg.JarIndexBug Tests:
        Results: locale=English (United States), bundleName=jarpkg.MyPropertyBundle
      java.util.MissingResourceException: Can't find bundle for base name
      jarpkg.MyPropertyBundle, locale en_US
      at
      java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:707)
      at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:670)
      at java.util.ResourceBundle.getBundle(ResourceBundle.java:559)
      at jarpkg.JarIndexBug.getBundle(jarpkg/JarIndexBug.java:51)
      at jarpkg.JarIndexBug.doTest(jarpkg/JarIndexBug.java:33)
      at jarpkg.JarIndexBug.main(jarpkg/JarIndexBug.java:22)

        Results: locale=Spanish, bundleName=jarpkg.MyPropertyBundle
          yes.msg="s?"
          no.msg="ning?n"
          maybe.msg="maybe"
      (Review ID: 104246)
      ======================================================================

            bristor Dave Bristor (Inactive)
            stompkinsunw Sean Tompkins (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: