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

characters are converted to integers or not depending on how you compile.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.2.2
    • tools
    • generic
    • generic



      Name: skT88420 Date: 08/11/99


      java full version "JDK1.1.8M"
      and SDK 1.2.2

      There are two source files -
      --- Begin file: TestJavaBug.java ----
      public class TestJavaBug {
      protected static final char OPTION_CLOSE = '>';
      }
      --- End file: TestJavaBug.java ----

      --- Begin file: TestJavaBugChild.java ----
      public class TestJavaBugChild extends TestJavaBug {
      public static void main(String args[]) {
      TestJavaBugChild child = new TestJavaBugChild();

      child.test();
      }

      protected void test() {
      char ch;
      String str = "Moo";
      str += OPTION_CLOSE;
      System.out.println(str);

      String str2 = "Moo";
      ch = OPTION_CLOSE;
      str2 += ch;
      System.out.println(str2);
      }

      // protected static final char OPTION_CLOSE = '>';
      }
      --- End file: JavaBugTestChild.java

      Depending on the order in which these files are compiled the
      program in JavaBugTestChild behaves differently. Here is some
      sample output, note that the code was not changed between
      compilations!

      D:\Java\FormatParser>del *.class

      D:\Java\FormatParser>javac TestJavaBug.java

      D:\Java\FormatParser>javac TestJavaBugChild.java

      D:\Java\FormatParser>java TestJavaBugChild
      Moo62
      Moo>

      D:\Java\FormatParser>del *.class

      D:\Java\FormatParser>javac TestJavaBugChild.java

      D:\Java\FormatParser>javac TestJavaBug.java

      D:\Java\FormatParser>java TestJavaBugChild
      Moo>
      Moo>

      Note that if TestJavaBugChild is compiled first then the program
      converts the character OPTION_CLOSE to it's ASCII number but
      when TestJavaBug is compiled first it uses it as a character
      like it's supposed to! This error only seems to occur when
      the character is inheritted from another module. You can play
      around with it if you like. I'm using a Windows NT machine.
      (Review ID: 93749)
      ======================================================================

            wmaddoxsunw William Maddox (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: