java/1958: Incorrect error message attempting to access non-final local from local class

bryce@albatross.co.nz bryce@albatross.co.nz
Mon Feb 12 22:56:00 GMT 2001


>Number:         1958
>Category:       java
>Synopsis:       Incorrect error message attempting to access non-final local from local class
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 12 22:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Bryce McKinlay
>Release:        gcc version 2.97 20010207 (experimental)
>Organization:
>Environment:

>Description:
The code below is illegal because x is non final in Local2.a().

gcj reports:

$ gcj -c Local2.java 
Local2.java: In class `Local2$I':
Local2.java: In method `Local2$I.b()':
Local2.java:8: Undefined variable `x'.
         int b() {return x;};    
                         ^
1 error


but the correct error (as reported by javac) is:

Local2.java:8: local variable x is accessed from within inner class; needs to be declared final
>How-To-Repeat:
public class Local2
{
  void a()
  {
    int x;
    class I
    {
      int b() {return x;};    
    }
  }
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list