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

(reflect) Field.toString() returns native modifier for elements of enum type

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs

      Description



      Name: vrR10176 Date: 01/30/2004



      The API spec (JDK1.5-b36) for method Field.toString() says:

      "public String toString()

        Returns a string describing this Field. The format is the access modifiers for
      the field, if any, followed by the field type, followed by a space, followed by
      the fully-qualified name of the class declaring the field, followed by a period,
      followed by the name of the field. For example:
        public static final int java.lang.Thread.MIN_PRIORITY
        private int java.io.FileDescriptor.fd

      The modifiers are placed in canonical order as specified by "The Java Language
      Specification". This is public, protected or private first, and then other modifiers
      in the following order: static, final, transient, volatile. "

      But the method sets method modifier 'native' for elements of an enumerated type.

      To reproduce the issue execute the following test.

      ------------ test.java -------------------------------
      import java.lang.reflect.Field;

      enum EnumClass001 {
          f1, f2;
      }

      public class test {
          public static void main(String argv[]) {
              try {
                  Class cl = Class.forName("EnumClass001");
                  Field f = cl.getField("f1");
                  System.out.println("Field.toString() prints: " + f.toString());
              } catch(Throwable e) {
                  System.out.println("unexpected exception " + e);
              }
          }
      }

      ------------ Logs ---------------------------------------------
      $javac -source 1.5 -d . test.java
      $
      $java -version
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b36)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b36, mixed mode)
      $
      $java test
      Field.toString() prints: public static final native EnumClass001 EnumClass001.f1
      $
      $
      -------------------------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              darcy Joe Darcy
              Reporter:
              rslasunw Rsla Rsla (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: