This is the mail archive of the frysk@sourceware.org mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: inner classes with fields names similar to outer class/method fields


Hi Andrew,

On Tue, 2007-07-03 at 11:34 -0400, Andrew Cagney wrote:
> Mark Wielaard wrote:
> > The anonymous
> > inner class that extends TaskEvent tries to refer to the final task
> > field of the method it is in. But TaskEvent has a field called task
> > itself. The TaskEvent.task field is never initialized and so stays null.
> > 
> Can you be more specific?

Look at the attached patch of the original message, in particular:

> -    final Task task = proc.getMainTask();
> +    final Task proc_task = proc.getMainTask();
> [...]
>      Manager.eventLoop.add(new TaskEvent()
>        {
>         public void execute ()
>         {
>           // Continue running (inside syscall),
>           // while attaching another syscall observer
> -         task.requestUnblock(syso);
> -         task.requestAddSyscallObserver(syso2);
> +         proc_task.requestUnblock(syso);
> +         proc_task.requestAddSyscallObserver(syso2);
>         }
>        });

Now look at TaskEvent:

> public abstract class TaskEvent
>     implements Event
> {
>     [...]
>     protected Task task;
> [...]

And ask yourself which 'task' is being referred to in the execute()
method of the anonymous class given to the add() method. Is it the final
field in the outer class method called task, or is it the inherited
protected field called task from the super class TaskEvent? The "right"
answer is the protected field task from the super class, but since that
is in a completely different file while the final field task in the
enclosing method looks like the only task in scope some confusion
ensues. Renaming (one of) the fields is the best solution seeing some
compilers also seem to get this one wrong.

Cheers,

Mark


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]