Bug 6576 - java.util.ResourceBundle.getResource ignores locale
Summary: java.util.ResourceBundle.getResource ignores locale
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 3.1
: P3 normal
Target Milestone: ---
Assignee: Tom Tromey
Depends on:
Reported: 2002-05-06 04:26 UTC by bruno
Modified: 2003-07-25 17:33 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description bruno 2002-05-06 04:26:04 UTC
The java.util.ResourceBundle.getBundle(String,Locale) function
appears to ignore the locale argument.

3.1 20020423 (prerelease)

System: Linux linuix 2.4.18-4GB #1 Wed Mar 27 13:57:05 UTC 2002 i686 unknown
Architecture: i686

host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../configure --prefix=/packages/gnu-snapshot --enable-shared --enable-version-specific-runtime-libs --enable-nls

$ export CLASSPATH=.
$ cat <<\EOF > prog_fr.java
/* Automatically generated by GNU msgfmt.  Do not modify!  */
public class prog_fr extends java.util.ResourceBundle {
  private static final java.util.Hashtable table;
  static {
    java.util.Hashtable t = new java.util.Hashtable();
    t.put("","Content-Type: text/plain; charset=UTF-8\nPlural-Forms: nplurals=2; plural=(n > 1);\n");
    t.put("'Your command, please?', asked the waiter.","\u00abVotre commande, s'il vous plait\u00bb, dit le gar\u00e7on.");
    t.put("a piece of cake",new java.lang.String[] { "un morceau de gateau", "{0,number} morceaux de gateau" });
    t.put("{0} is replaced by {1}.","{1} remplace {0}.");
    table = t;
  public static final java.util.Hashtable plural;
  static {
    java.util.Hashtable p = new java.util.Hashtable();
    p.put("a piece of cake","{0,number} pieces of cake");
    plural = p;
  public java.lang.Object lookup (java.lang.String msgid) {
    return table.get(msgid);
  public java.lang.Object handleGetObject (java.lang.String msgid) throws java.util.MissingResourceException {
    java.lang.Object value = table.get(msgid);
    return (value instanceof java.lang.String[] ? ((java.lang.String[])value)[0] : value);
  public java.util.Enumeration getKeys () {
    return table.keys();
  public static long pluralEval (long n) {
    return ((n > 1) ? 1 : 0);
  public java.util.ResourceBundle getParent () {
    return parent;
$ gcj -C -O -d . prog_fr.java
$ cat <<\EOF > DumpResource.java
import java.lang.reflect.*;
import java.util.*;
import java.io.*;
public class DumpResource {
  public DumpResource (String resource_name, String locale_name) {
    // Split locale_name into language_country_variant.
    String language;
    String country;
    String variant;
    language = locale_name;
      int i = language.indexOf('_');
      if (i >= 0) {
        country = language.substring(i+1);
        language = language.substring(0,i);
      } else
        country = "";
      int j = country.indexOf('_');
      if (j >= 0) {
        variant = country.substring(j+1);
        country = country.substring(0,j);
      } else
        variant = "";
    Locale locale = new Locale(language,country,variant);
    // Get the resource.
    System.out.println("Calling getBundle("+resource_name+","+locale+").");
    ResourceBundle catalog = ResourceBundle.getBundle(resource_name,locale);
  public static void main (String[] args) {
    new DumpResource(args[0], args.length > 1 ? args[1] : "");
$ gcj -C -O -d . DumpResource.java
$ gij DumpResource prog fr
Calling getBundle(prog,fr).
Exception in thread "main" java.util.MissingResourceException: Bundle prog not found
   at 0x4025bf70: java.lang.Throwable.Throwable(java.lang.String) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x4024aed6: java.lang.Exception.Exception(java.lang.String) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x4024fba6: java.lang.RuntimeException.RuntimeException(java.lang.String) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x402a0ea9: java.util.MissingResourceException.MissingResourceException(java.lang.String, java.lang.String, java.lang.String) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x402a4ec9: java.util.ResourceBundle.getBundle(java.lang.String, java.util.Locale, java.lang.ClassLoader) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x402a495b: java.util.ResourceBundle.getBundle(java.lang.String, java.util.Locale) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x403d76e7: ffi_call_SYSV (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x403d7697: ffi_raw_call (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x4022e20b: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x403e2644: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x4022c024: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x403d754c: ?? (??:0)
   at 0x403d76e7: ffi_call_SYSV (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x403d7697: ffi_raw_call (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x4022e20b: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x403e2644: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x4022c024: _Jv_InBFD: Dwarf Error: Invalid or unhandled FORM value: 14.
BFD: Dwarf Error: Invalid or unhandled FORM value: 14.
BFD: Dwarf Error: Invalid or unhandled FORM value: 14.
BFD: Dwarf Error: Invalid or unhandled FORM value: 14.
terpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x403d754c: ?? (??:0)
   at 0x40232408: gnu.gcj.runtime.FirstThread.call_main() (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x402bab18: gnu.gcj.runtime.FirstThread.run() (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x4023dbcc: _Jv_ThreadRun(java.lang.Thread) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x4021a2c4: _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/packages/gnu-snapshot/lib/libgcj.so.3)
   at 0x08048a20: main (get_vector/../../../libjava/gij.cc:140)
   at 0x405de668: __libc_start_main (/lib/libc.so.6)
   at 0x08048781: _start (??:0)

When I look (using strace) what files gij is trying to open(),
I see that it searching for "./prog.properties" and "./prog.class"
but not for "./prog_fr.properties" and "./prog_fr.class". It should
search first for "./prog_fr.properties" and "./prog_fr.class" and
then only for "./prog.properties" and "./prog.class".
Comment 1 bruno 2002-05-06 04:26:04 UTC
Fix the internal working of this function.
Comment 2 Tom Tromey 2002-05-06 16:32:48 UTC
Responsible-Changed-From-To: unassigned->tromey
Responsible-Changed-Why: I'm handling this.
Comment 3 Tom Tromey 2002-05-06 16:32:48 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: The problem here is that there is no "prog" bundle available.
    Whoever wrote our ResourceBundle interpreted the online docs
    as requiring "prog" if "prog_foo" is provided.
    I'm not certain that this is the most robust interpretation,
    but it may be defensible.
    I note that the JDK works correctly in this scenario.
    So, I'm inclined to agree this is a bug.
    I don't know when I can work on it; meanwhile at least we know of a workaround.
Comment 4 Tom Tromey 2002-09-23 10:58:56 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: I've checked in a fix for this.
Comment 5 Tom Tromey 2002-09-23 17:56:34 UTC
From: tromey@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Subject: libgcj/6576
Date: 23 Sep 2002 17:56:34 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	tromey@gcc.gnu.org	2002-09-23 10:56:34
 Modified files:
 	libjava        : ChangeLog 
 	libjava/java/util: ResourceBundle.java 
 Log message:
 	Fix for PR libgcj/6576:
 	* java/util/ResourceBundle.java (tryBundle): Cache `null' if we
 	didn't find a given bundle.
 	(getBundle): Don't require base bundle.
 	(setParent): Removed old comment.
 	(tryLocalBundle): Try components even if preceding components were