Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Eclipse bug: Doesn't check for uninitialized variables when there are "too many" variable declarations.

Reply
Thread Tools

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

 
 
Oliver Wong
Guest
Posts: n/a
 
      04-18-2006
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

 
Reply With Quote
 
 
 
 
Andrew McDonagh
Guest
Posts: n/a
 
      04-18-2006

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.





Oliver Wong wrote:
> 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

 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      04-18-2006
Oliver Wong <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      04-18-2006


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.

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      04-18-2006
Mark Thomas wrote:
> Oliver Wong wrote:
>> 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
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
James McGill
Guest
Posts: n/a
 
      04-18-2006
On Tue, 2006-04-18 at 16:44 +0000, Oliver Wong wrote:
>
> 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.

 
Reply With Quote
 
Mark Thomas
Guest
Posts: n/a
 
      04-18-2006
Oliver Wong wrote:
> 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

 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      04-18-2006

"James McGill" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) n...
> On Tue, 2006-04-18 at 16:44 +0000, Oliver Wong wrote:
>>
>> 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.


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

 
Reply With Quote
 
James McGill
Guest
Posts: n/a
 
      04-18-2006
On Tue, 2006-04-18 at 18:22 +0000, Oliver Wong wrote:
>
>
> What version of Eclipse are you using?


Whatever today's Milestone build happens to be

 
Reply With Quote
 
Andrew McDonagh
Guest
Posts: n/a
 
      04-18-2006
Eric Sosman wrote:
>
> 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.
>


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialized and Uninitialized Global Variables and Executable FileSize C.S.M.G.Sarma C Programming 6 07-15-2010 03:06 PM
Have Ruby warnings about uninitialized instance variables gotten more verbose in the past year? Bill McNeill Ruby 1 10-18-2007 03:08 AM
Uninitialized auto variables Spoon C Programming 22 08-26-2007 07:18 AM
handling uninitialized pointed (How to check ?? ) sanjaymeher@gmail.com C Programming 21 12-29-2005 11:39 AM
Detecting Reads of Global Uninitialized Variables jyu.james@gmail.com C Programming 12 10-01-2005 04:46 PM



Advertisments