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

Discussion in 'Java' started by Oliver Wong, Apr 18, 2006.

  1. Oliver Wong

    Oliver Wong Guest

    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
     
    Oliver Wong, Apr 18, 2006
    #1
    1. Advertising

  2. Re: Eclipse bug: Doesn't check for uninitialized variables when thereare "too many" variable declarations.

    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
     
    Andrew McDonagh, Apr 18, 2006
    #2
    1. Advertising

  3. Oliver Wong

    Chris Smith Guest

    Oliver Wong <> 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
     
    Chris Smith, Apr 18, 2006
    #3
  4. Oliver Wong

    Eric Sosman Guest

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

    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.

    --
     
    Eric Sosman, Apr 18, 2006
    #4
  5. Re: Eclipse bug: Doesn't check for uninitialized variables when thereare "too many" variable declarations.

    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/
     
    Thomas Hawtin, Apr 18, 2006
    #5
  6. Oliver Wong

    James McGill Guest

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

    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.
     
    James McGill, Apr 18, 2006
    #6
  7. Oliver Wong

    Mark Thomas Guest

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

    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
     
    Mark Thomas, Apr 18, 2006
    #7
  8. Oliver Wong

    Oliver Wong Guest

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

    "James McGill" <> wrote in message
    news:...
    > 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
     
    Oliver Wong, Apr 18, 2006
    #8
  9. Oliver Wong

    James McGill Guest

    Re: Eclipse bug: Doesn't check for uninitialized variableswhenthere are "too many" variable declarations.

    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 ;-)
     
    James McGill, Apr 18, 2006
    #9
  10. Re: Eclipse bug: Doesn't check for uninitialized variables when thereare "too many" variable declarations.

    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.
     
    Andrew McDonagh, Apr 18, 2006
    #10
  11. Oliver Wong

    Mark Thomas Guest

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

    Thomas Hawtin wrote:
    > 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

    When I say it works fine, I meant eclipse highlights the error!

    Mark
     
    Mark Thomas, Apr 19, 2006
    #11
  12. Re: Eclipse bug: Doesn't check for uninitialized variables when thereare "too many" variable declarations.

    -----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-----
     
    Hendrik Maryns, Apr 19, 2006
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Valentin Tihomirov
    Replies:
    3
    Views:
    545
    Jim Lewis
    Oct 23, 2003
  2. peelman

    How many threads is too many?

    peelman, Jan 13, 2005, in forum: Java
    Replies:
    12
    Views:
    843
    Esmond Pitt
    Jan 15, 2005
  3. Rhino
    Replies:
    33
    Views:
    1,315
    Oliver Wong
    Dec 22, 2005
  4. rbt
    Replies:
    1
    Views:
    356
  5. Dag Sunde
    Replies:
    4
    Views:
    361
Loading...

Share This Page