A bug with automatic variables and finally

Gary Howland gary at systemics.com
Fri Apr 18 18:01:47 PDT 1997


Hi,

This appears to be a bug:

    public class Finally
    {
        public Finally() {}

        public void
        x()
        {
            int i = 3;

            try {
                ((Object)null).toString();
            }
            finally {
                System.out.println("i = "+i);
            }
        }

        public static void
        main(String[] args)
        {
            new Finally().x();
        }
    }

When run, 'i' no longer has the value 3 it appears to be rubbish.
The Sun JDK seems to work OK.  I have yet to try netscape and Microsoft.

However, if I add the line 'System.out.println("i = "+i);' after the line
'int i =3', then it works.  Perhaps something is being optimised away?

Also interesting, is if the line '((Object)null).toString();' is changed to
'throw new RuntimeException("Doh!");', then there is no problem.  So it 
appears that there is a difference in runtime exceptions!

I am running kaffe 0.8.4.

(What is the flag to run in interpreted mode?)


Gary
-- 
pub  1024/C001D00D 1996/01/22  Gary Howland <gary at systemics.com>
Key fingerprint =  0C FB 60 61 4D 3B 24 7D  1C 89 1D BE 1F EE 09 06 
[ Currently available for Java contracts - will travel anywhere ]




More information about the kaffe mailing list