Bug 137298 - [compiler] Local variables not reported as not been initialized when more than 64 locals are defined
Summary: [compiler] Local variables not reported as not been initialized when more tha...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.2 RC2   Edit
Assignee: Maxime Daniel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-18 12:52 EDT by Oliver Wong CLA
Modified: 2006-04-28 14:33 EDT (History)
1 user (show)

See Also:


Attachments
Patch - under test for now (920 bytes, patch)
2006-04-19 01:30 EDT, Maxime Daniel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Wong CLA 2006-04-18 12:52:09 EDT
My Eclipse version is 3.2.0 build ID is I20060217-1115.

Here's a test code:

<code>
public class TestCase {

  public static void main(String[] args) {
    {
      int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
      int aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as, at, au, av, aw, ax, ay, az;
      int ba, bb, bc, bd, be, bf, bg, bh, bi, bj, bk, bl, bm, bn, bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz;
    }
    {
      Object fromToken = null;
      Object toToken = null;
      String fromString;
      if (fromToken != null) {
        fromString = "";
      }
      String toString;
      if (toToken != null) {
        toString = "";
      }
      System.out.println(fromString);
      System.out.println(toString);
    }
  }
}
</code>

If you try to compile this with Sun's JavaC, it reports two compile errors saying that fromString and toString might not have been initialized when the println() occurs.

If you put this into Eclipse, Eclipse will compile it, and when you try to run the class file produced by Eclipse, the JVM will throw an java.lang.Verify error.

It looks like Eclipse "stops checking" when you declare too many variables. These can be local variables, or fields of the class. Try commenting out some of the useless variable declarations, and Eclipse will correctly detect that the two strings are uninitialized.
Comment 1 Olivier Thomann CLA 2006-04-18 17:19:30 EDT
If the source is changed for:
public class X {

	public static void main(String[] args) {
			int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
			int aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as, at, au, av, aw, ax, ay, az;
			int ba, bb, bc, bd, be, bf, bg, bh; //, bi, bj, bk, bl, bm, bn, bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz;
			Object fromToken = null;
			Object toToken = null;
			String fromString;
			if (fromToken != null) {
				fromString = "";
			}
			String toString;
			if (toToken != null) {
				toString = "";
			}
			System.out.println(fromString);
			System.out.println(toString);
	}
}

Then both toString and fromString are reported as not been initialized.
If changed to:

public class X {

	public static void main(String[] args) {
			int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
			int aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as, at, au, av, aw, ax, ay, az;
			int ba, bb, bc, bd, be, bf, bg, bh, bi; //, bj, bk, bl, bm, bn, bo, bp, bq, br, bs, bt, bu, bv, bw, bx, by, bz;
			Object fromToken = null;
			Object toToken = null;
			String fromString;
			if (fromToken != null) {
				fromString = "";
			}
			String toString;
			if (toToken != null) {
				toString = "";
			}
			System.out.println(fromString);
			System.out.println(toString);
	}
}

Only fromString is reported as not been initialized.

The limit seems to be 64. Could this be related to how the bits are set in the flow context?
Comment 2 Maxime Daniel CLA 2006-04-19 01:12:09 EDT
My mistake: one branch in UnconditionalFlowInfo#mergedWith doesn't complete its job properly.
Comment 3 Maxime Daniel CLA 2006-04-19 01:29:45 EDT
Added FlowAnalysis test #26 (not activated for now).
Comment 4 Maxime Daniel CLA 2006-04-19 01:30:23 EDT
Created attachment 38890 [details]
Patch - under test for now
Comment 5 Philipe Mulet CLA 2006-04-19 04:35:56 EDT
+1 for 3.2RC2
Comment 6 Maxime Daniel CLA 2006-04-19 08:40:47 EDT
Fixed and released in HEAD.
Verifier pls use the test cases provided by the reporter and/or Olivier, or else FlowAnalysisTest #26.
Comment 7 Olivier Thomann CLA 2006-04-28 14:33:51 EDT
Verified with I20060427-1600 for 3.2RC2