Bug 19677

Summary: invalid "may not have been initialized" error
Product: gcc Reporter: Jerry Haltom <wasabi>
Component: javaAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, java-prs
Priority: P2 Keywords: diagnostic, rejects-valid
Version: 4.0.0   
Target Milestone: 4.3.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2005-05-01 02:37:39
Bug Depends on: 28067    
Bug Blocks:    

Description Jerry Haltom 2005-01-28 19:21:52 UTC
Following Eclipse code snippet that fails:

protected void join(InternalJob job) {
	final IJobChangeListener listener;

	synchronized (lock) {
		listener = new JobChangeAdapter() {
			public void done(IJobChangeEvent event) {
				barrier.release();
			}
		};
		job.addJobChangeListener(listener);
	}
}

The error reports the line containing listener = as the problem.
Comment 1 Jerry Haltom 2005-01-28 19:23:53 UTC
Oh yes, of course:

runtime.jar:
    [mkdir] Created dir:
/tmp/ram/eclipse-3.0.1/source-tree/plugins/org.eclipse.core.runtime/temp.folder/runtime.jar.bin
    [javac] Compiling 158 source files to
/tmp/ram/eclipse-3.0.1/source-tree/plugins/org.eclipse.core.runtime/temp.folder/runtime.jar.bin
    [javac]
/tmp/ram/eclipse-3.0.1/source-tree/plugins/org.eclipse.core.runtime/src/org/eclipse/core/internal/jobs/JobManager.java:
In class `org.eclipse.core.internal.jobs.JobManager':
    [javac]
/tmp/ram/eclipse-3.0.1/source-tree/plugins/org.eclipse.core.runtime/src/org/eclipse/core/internal/jobs/JobManager.java:
In method
`org.eclipse.core.internal.jobs.JobManager.join(org.eclipse.core.internal.jobs.InternalJob)':
    [javac]
/tmp/ram/eclipse-3.0.1/source-tree/plugins/org.eclipse.core.runtime/src/org/eclipse/core/internal/jobs/JobManager.java:548:
error: Variable `listener' may not have been initialized.
    [javac]                     };
    [javac]    ^
    [javac] 1 error
Comment 2 Andrew Pinski 2005-01-28 19:35:32 UTC
Confirmed, reduced to:
class a1 { public int f(){return 1;} }
class t
{
  Object f;
  void g(a1 a)  {}
  void f()
  {
    final a1 a;
    a = new a1 () { public int f(){return 0;}};
    g(a);
  }
}
Comment 3 Andrew Pinski 2005-01-28 19:43:06 UTC
Related to bug 16839.  The problem might be the same problem after all because final are collected for 
anonymous inner classes.
Comment 4 Tom Tromey 2005-01-30 19:02:56 UTC
Yes, the underlying problem is the same as with bug 16839.
gcj captures all 'final' local variables in an anonymous class.
This is incorrect -- it should only capture those which are actually
used.
Comment 5 Tom Tromey 2007-01-09 20:46:59 UTC
All gcj front end bugs have been fixed by the gcj-eclipse branch merge.
I'm mass-closing the affected PRs.
If you believe one of these was closed in error, please reopen it
with a note explaining why.
Thanks.