public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
* inner classes with fields names similar to outer class/method  fields
@ 2007-07-02 12:32 Mark Wielaard
  2007-07-03 15:34 ` Andrew Cagney
  2007-07-05 18:43 ` Andrew Cagney
  0 siblings, 2 replies; 6+ messages in thread
From: Mark Wielaard @ 2007-07-02 12:32 UTC (permalink / raw)
  To: frysk

Hi,

The following bug cost me a while to track down. The fix is easy. But if
you are not expecting this then you might be puzzled about it for a long
time like I was.

testSyscallRunning(frysk.proc.TestSyscallRunning)java.lang.NullPointerException
   at frysk.proc.TestSyscallRunning$2.execute(TestRunner)

The problem was that under some versions of the fc6 compiler this method
was miscompiled (!), under f7 the compiler gets it right. 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.
By explicitly renaming the final field in the outer method and using
that name in the inner class the reference is always correct (under
either the fc6 or f7 compiler).

2007-06-02  Mark Wielaard  <mwielaard@redhat.com>

        * TestSyscallRunning.java (testSyscallRunning): 
        Rename final task field to proc_task.

There should be a warning in the compiler to complain if such a
confusing name clash is detected.

Cheers,

Mark

diff -u -r1.12 TestSyscallRunning.java
--- frysk/proc/TestSyscallRunning.java  17 Apr 2007 19:45:09 -0000      1.12
+++ frysk/proc/TestSyscallRunning.java  2 Jul 2007 12:16:10 -0000
@@ -103,10 +103,10 @@
     // Get the port that will be listened on.
     int port = Integer.decode(in.readLine()).intValue();
 
-    final Task task = proc.getMainTask();
+    final Task proc_task = proc.getMainTask();
 
-    final SyscallObserver syso = new SyscallObserver("accept", task, false);
-    task.requestAddSyscallObserver(syso);
+    final SyscallObserver syso = new SyscallObserver("accept", proc_task, false
);
+    proc_task.requestAddSyscallObserver(syso);
 
     // Make sure the observer is properly installed.
     while (! syso.isAdded())
@@ -122,15 +122,15 @@
 
     // Now unblock and then attach another observer.
     // Do all this on the eventloop so properly serialize calls.
-    final SyscallObserver syso2 = new SyscallObserver("accept", task, true);
+    final SyscallObserver syso2 = new SyscallObserver("accept", proc_task, true
);
     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);
        }
       });


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-07-05 18:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-02 12:32 inner classes with fields names similar to outer class/method fields Mark Wielaard
2007-07-03 15:34 ` Andrew Cagney
2007-07-03 17:27   ` Mark Wielaard
2007-07-03 18:44     ` Andrew Cagney
2007-07-03 19:21       ` Mark Wielaard
2007-07-05 18:43 ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).