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

Class.getField()/getDeclaredField() doesn't find non-ASCII field name

XMLWordPrintable

    • 1.1fcs
    • generic
    • generic
    • Not verified


      masayoshi.okutsu@Eng 1996-12-20
      A field name in non-ASCII characters cannot be found using
      Class.getField() or Class.getDeclaredField().

      To reproduce, run the following:

      Source program:

      import java.lang.reflect.*;

      public class fieldmini{
      //
      public static void main(String[] args){
      Field field;
      testField testfield = new testField();
      Class c = testfield.getClass();
      String fieldName = "\u30c6\u30b9\u30c8";
      //
      // getField()
      //
      try{
      field = c.getField(fieldName);
      }
      catch(NoSuchFieldException e){ e.printStackTrace(); }
      catch(SecurityException e){ e.printStackTrace(); }
      //
      // getDeclaredField()
      //
      try{
      field = c.getDeclaredField(fieldName);
      }
      catch(NoSuchFieldException e){ e.printStackTrace(); }
      catch(SecurityException e){ e.printStackTrace(); }
      }
      }

      //
      // class testField
      //
      class testField{
      public final static int \u30c6\u30b9\u30c8 = 0;
      public testField(){}
      public static void test(){}
      }

      Execution result:

      % java fieldmini
      java.lang.NoSuchFieldException
      at java.lang.Class.getField(Class.java)
      at fieldmini.main(fieldmini.java:14)
      java.lang.NoSuchFieldException
      at java.lang.Class.getDeclaredField(Class.java)
      at fieldmini.main(fieldmini.java:22)


      masayoshi.okutsu@Eng 1996-12-20
      See also the attachment. It tests non-ascii names for a class. (Written in EUCJIS)

            nsaraiyasunw Nakul Saraiya (Inactive)
            okutsu Masayoshi Okutsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: