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]

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


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);
        }
       });



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