Eclipse bug: Doesn't check for uninitialized variables when there are "too many" variable declaratio

O

Oliver Wong

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
 
A

Andrew McDonagh

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.
 
C

Chris Smith

Oliver Wong said:
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... :)

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
E

Eric Sosman

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.
 
T

Thomas Hawtin

Mark said:
Oliver said:
Object toToken = null;
[...]
String toString;
if (toToken != null) {
toString = "";
}
[...]
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
 
J

James McGill

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.
 
M

Mark Thomas

Oliver said:
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
Works fine at Eclipse 3.1.0.

Mark
 
O

Oliver Wong

James McGill said:
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.

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
 
A

Andrew McDonagh

Eric said:
Andrew McDonagh wrote On 04/18/06 12:57,:

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.

doh - I meant Eclipse - might fix it when the Sun has burnt out.
 
M

Mark Thomas

Thomas said:
Mark said:
Oliver said:
Object toToken = null;
[...]
String toString;
if (toToken != null) {
toString = "";
}
[...]
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
When I say it works fine, I meant eclipse highlights the error!

Mark
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFERgWOe+7xMGD3itQRAp0uAJ9IF7BFGZyBliK4WZZ2sim2rmUYWwCfYWQc
H9K8CEXDXWaqEjAG7WiJ2CE=
=c25b
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top