Re: JDK 1.4.2 javac compiler bug with final local variables?

Discussion in 'Java' started by Jon Skeet, Jul 3, 2003.

  1. Jon Skeet

    Jon Skeet Guest

    xarax <> wrote:
    > Anyone notice this problem with the JDK 1.4.2. javac?
    >
    > I get an error message about the final variable
    > may have already been assigned. This compiled
    > fine just last week with 1.4.1 javac from Sun.
    >
    > It happens for some, but not all final local
    > variables. The source code has *NOT* changed
    > from last week. The only change is the new
    > javac compiler for Sun JDK 1.4.2.
    >
    > The source code is correct. Has this been reported?


    Could you give a short but complete example which demonstrates the
    problem?

    --
    Jon Skeet - <>
    http://www.pobox.com/~skeet/
    If replying to the group, please do not mail me too
    Jon Skeet, Jul 3, 2003
    #1
    1. Advertising

  2. Jon Skeet

    xarax Guest

    Jon Skeet <> wrote in message news:<>...
    > xarax <> wrote:
    > > Anyone notice this problem with the JDK 1.4.2. javac?
    > >
    > > I get an error message about the final variable
    > > may have already been assigned. This compiled
    > > fine just last week with 1.4.1 javac from Sun.
    > >
    > > It happens for some, but not all final local
    > > variables. The source code has *NOT* changed
    > > from last week. The only change is the new
    > > javac compiler for Sun JDK 1.4.2.
    > >
    > > The source code is correct. Has this been reported?

    >
    > Could you give a short but complete example which demonstrates the
    > problem?


    ===================================
    public void fubar()
    {
    final int xx;
    int jj;

    jj = 0;
    while(0 != jj)
    {
    final int nn;

    nn = jj+1;
    }

    if(0 < jj)
    {
    xx = 1;
    }
    else
    {
    xx = 2;
    }
    }
    ===================================

    removing either "final" qualifier circumvents
    the problem. the compiler complains about the
    assigned to "xx". it appears that the "final"
    qualifier within the while() loop is somehow
    confusing the compiler.
    xarax, Jul 3, 2003
    #2
    1. Advertising

  3. Jon Skeet

    Jon Skeet Guest

    xarax <> wrote:

    <snip>

    > removing either "final" qualifier circumvents
    > the problem. the compiler complains about the
    > assigned to "xx". it appears that the "final"
    > qualifier within the while() loop is somehow
    > confusing the compiler.


    Not on my box - which 1.4.2 are you using? Here's the compete code of
    the test program which compiles on my 1.4.2 installation:

    public class Test
    {
    public void fubar()
    {
    final int xx;
    int jj;

    jj = 0;
    while(0 != jj)
    {
    final int nn;

    nn = jj+1;
    }

    if(0 < jj)
    {
    xx = 1;
    }
    else
    {
    xx = 2;
    }
    }
    }

    --
    Jon Skeet - <>
    http://www.pobox.com/~skeet/
    If replying to the group, please do not mail me too
    Jon Skeet, Jul 3, 2003
    #3
  4. Jon Skeet

    xarax Guest

    David Zimmerman <> wrote in message news:<>...
    > xarax wrote:
    > > Jon Skeet <> wrote in message news:<>...
    > >
    > >>xarax <> wrote:
    > >>
    > >>>Anyone notice this problem with the JDK 1.4.2. javac?
    > >>>
    > >>>I get an error message about the final variable
    > >>>may have already been assigned. This compiled
    > >>>fine just last week with 1.4.1 javac from Sun.
    > >>>
    > >>
    > >>Could you give a short but complete example which demonstrates the
    > >>problem?

    > >
    > >
    > > ===================================
    > > public void fubar()
    > > {
    > > final int xx;
    > > int jj;
    > >
    > > jj = 0;
    > > while(0 != jj)
    > > {
    > > final int nn;
    > >
    > > nn = jj+1;
    > > }
    > >
    > > if(0 < jj)
    > > {
    > > xx = 1;
    > > }
    > > else
    > > {
    > > xx = 2;
    > > }
    > > }

    >
    > Perhaps he's complaining about nn gettingassigned more than once. That
    > while loop might run more than once.


    The message clearly indicates "xx" is the problem. The message
    appears for each assignment to "xx". When I remove either "final"
    qualifier, it compiles fine.

    The "final" within the loop simply means that the variable
    can only be assigned once per pass.

    This is Sun JDK 1.4.2 installed on WindowsME.
    xarax, Jul 3, 2003
    #4
  5. "xarax" <> wrote in message
    news:...
    > Jon Skeet <> wrote in message

    news:<>...
    > > Could you give a short but complete example which demonstrates the
    > > problem?

    >
    > ===================================
    > public void fubar()

    ...snip...
    > }
    > }
    > ===================================
    >
    > removing either "final" qualifier circumvents
    > the problem. the compiler complains about the
    > assigned to "xx". it appears that the "final"
    > qualifier within the while() loop is somehow
    > confusing the compiler.


    The code compiles fine over here, using Java 1.4.2-b28
    Maybe something is wrong with your config, or maybe you are using a beta of
    1.4.2?

    Cheers,
    Erwin
    Erwin Molendyk, Jul 4, 2003
    #5
  6. Jon Skeet

    xarax Guest

    Jon Skeet <> wrote in message news:<>...
    > xarax <> wrote:
    > > This is Sun JDK 1.4.2 installed on WindowsME.

    >
    > *Which* 1.4.2 though? Final, or a beta?
    >
    > Has anyone else seen this *not* compile?


    The final (pun?) 1.4.2 JDK. ;)

    I was using 1.4.1-02 prior to installing 1.4.2, so
    maybe the windoze installation screwed up something
    (like mixing different levels javac runtime class
    libraries?). If it's not something obvious on my end,
    then I'll have to wait until someone else can
    recreate the bug.
    xarax, Jul 4, 2003
    #6
    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. xarax
    Replies:
    1
    Views:
    1,469
    Andy Flowers
    Jul 2, 2003
  2. Miss Michelle. Heigardt
    Replies:
    8
    Views:
    143,133
    abbinv
    Apr 9, 2011
  3. Dean Schulze
    Replies:
    7
    Views:
    9,316
    Thomas Hawtin
    Feb 28, 2006
  4. Frank Fredstone

    jdk 1.4.2 javac and java.endorsed dirs

    Frank Fredstone, Jun 22, 2006, in forum: Java
    Replies:
    0
    Views:
    1,378
    Frank Fredstone
    Jun 22, 2006
  5. Marc van Dongen

    Compiler Bug?? (javac 1.6.0_0-internal)

    Marc van Dongen, Dec 21, 2008, in forum: Java
    Replies:
    12
    Views:
    973
    Andrew Thompson
    Dec 28, 2008
Loading...

Share This Page