Java Forum / General / April 2006
Eclipse bug: Doesn't check for uninitialized variables when there are "too many" variable declarations.
Oliver Wong - 18 Apr 2006 17:44 GMT This is just as a heads up for other people using Eclipse who might run into this bug. I got stuck on it while working on a project, and waste an hour or so tracking down the cause.
My Eclipse version is 3.2.0 build ID is I20060217-1115.
Here's the 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.
I've already filed this with Eclipse's bug tracker: https://bugs.eclipse.org/bugs/show_bug.cgi?id=137298
- Oliver
Andrew McDonagh - 18 Apr 2006 17:57 GMT Wow - thankfully I'll never see this bug as I'd never create a design that used as many vars.
I'm sure Sun will 'fix' this bug sometime when our own sun burns a little less bright.
> This is just as a heads up for other people using Eclipse who might > run into this bug. I got stuck on it while working on a project, and [quoted text clipped - 51 lines] > > - Oliver Eric Sosman - 18 Apr 2006 18:34 GMT Andrew McDonagh wrote On 04/18/06 12:57,:
> Wow - thankfully I'll never see this bug as I'd never create a design > that used as many vars. > > I'm sure Sun will 'fix' this bug sometime when our own sun burns a > little less bright. Um, er, is there some special reason you think Sun will fix this bug, or ought to fix this bug, or even ought to be asked to fix this bug? We've got enough bugs of our own, thanks, without being asked to take on someone else's.
 Signature Eric.Sosman@sun.com
Andrew McDonagh - 18 Apr 2006 23:32 GMT > Andrew McDonagh wrote On 04/18/06 12:57,: >> Wow - thankfully I'll never see this bug as I'd never create a design [quoted text clipped - 8 lines] > bugs of our own, thanks, without being asked to take > on someone else's. doh - I meant Eclipse - might fix it when the Sun has burnt out.
Chris Smith - 18 Apr 2006 18:00 GMT > 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. Weird... :)
 Signature www.designacourse.com The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation
James McGill - 18 Apr 2006 18:58 GMT > 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; Well, not to argue that it's a bug, but if you have this situation in your code, it's a sure indication that you should consider a data structure of some type, or an array with a procedure to initialize the array contents.
I thought Eclipse was just calling the javac that you specify in workbench properties. Wouldn't that make this a Sun javac bug?
Besides that, your example is caught by my eclipse environment, no problem.
Oliver Wong - 18 Apr 2006 19:22 GMT >> int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, >> u, v, [quoted text clipped - 4 lines] > structure of some type, or an array with a procedure to initialize the > array contents. The Java source file I was working with was generated by another program (JavaCC, to be precise: https://javacc.dev.java.net/), so refactoring the class was not an option (generally, you shouldn't edit generated files at all). I suppose I could politely ask the JavaCC devs to generate "prettier" code...
> I thought Eclipse was just calling the javac that you specify in > workbench properties. Wouldn't that make this a Sun javac bug? No, Suns JavaC correctly detects the error. Eclipse uses its own internal compiler. Eclipses compiler has a different interpretation of how inferred generic types are handled, for example; in that specific case, I find the Eclipse compilers behaviour more "useful" than Suns JavaC behaviour.
> Besides that, your example is caught by my eclipse environment, no > problem. What version of Eclipse are you using?
- Oliver
James McGill - 18 Apr 2006 20:59 GMT > What version of Eclipse are you using? Whatever today's Milestone build happens to be ;-)
Mark Thomas - 18 Apr 2006 19:13 GMT > This is just as a heads up for other people using Eclipse who might > run into this bug. I got stuck on it while working on a project, and [quoted text clipped - 51 lines] > > - Oliver Works fine at Eclipse 3.1.0.
Mark
Thomas Hawtin - 18 Apr 2006 18:43 GMT >> Object toToken = null; >> [...] [quoted text clipped - 4 lines] >> [...] >> System.out.println(toString);
> Works fine at Eclipse 3.1.0. It shouldn't. The code is not correct. The compiler should catch that. Therefore it appears that there is a bug in the compiler used by Eclipse.
Neither toToken nor (in JLS2 with errata or JLS3) null is a compile-time constant expression, so toToken != null certainly is not.
Tom Hawtin
 Signature Unemployed English Java programmer http://jroller.com/page/tackline/
Mark Thomas - 19 Apr 2006 08:49 GMT >>> Object toToken = null; >>> [...] [quoted text clipped - 14 lines] > > Tom Hawtin When I say it works fine, I meant eclipse highlights the error!
Mark
Hendrik Maryns - 19 Apr 2006 10:40 GMT Oliver Wong schreef:
> This is just as a heads up for other people using Eclipse who might > run into this bug. I got stuck on it while working on a project, and > waste an hour or so tracking down the cause. > > My Eclipse version is 3.2.0 build ID is I20060217-1115. 3.2.0 build ID I20051215-1506 gets it correct, seems like a very recent bug, then.
H.
- -- Hendrik Maryns
================== www.lieverleven.be http://aouw.org
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|