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

javac seems to treat wrongly about non a constant field or expression.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.0
    • tools
    • x86
    • windows_nt



      Name: diC59631 Date: 02/24/98


      To repro:
      1 compile both of S.java and C.java
      2 run C#main ; "foo96" will be printed as expected
      3 change a value of jj from 6 to 5;
      4 re-compile only S.java
      5 and run
      expected : "foo95" printed
      actual: "foo96" printed

      "new S().ii" is NOT a constant expression(JLS15.27).
      Plus S#jj is NOT a constant field(JLS13.4.8,12.4.1) since it's not
      "static".
      However javac seems to treat it as if it's a constant field or
      expression.


      // S.java
      class S {
              static final String x = "foo";
              static final int ii = 9;
              final int jj = 6;
      }

      // C.java
      public class C extends S {
             static public void main(String []args) {
      C c = new C();
      c.doit();
      }
      void doit() {
                     String s = new S().x; // x is constant or not?
                     int b = new S().ii; // ii is constant or not?
                     int x = new S().jj; // <----------should NOT a constant
                     System.out.println(s + b + x);
            }
      }
      (Review ID: 25522)
      ======================================================================

            gafter Neal Gafter (Inactive)
            dindrigo Daniel Indrigo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: