This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


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

Patch: Fix PR 289


The JDK will exit with status 1 if any thread has thrown an uncaught
exception, unless System.exit() is called explicitly. This patch
implements this behaviour.

regards

  [ bryce ]

2000-09-13  Bryce McKinlay  <bryce@albatross.co.nz>

	Fix for PR libgcj/289:
	* java/lang/ThreadGroup.java (had_uncaught_exception): New field.
	(uncaughtException): Set had_uncaught_exception.
	* prims.cc (JvRunMain): Check value of had_uncaught_exception and
	exit with error status if set.
	(_Jv_RunMain): Ditto.

Index: prims.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/prims.cc,v
retrieving revision 1.35
diff -u -r1.35 prims.cc
--- prims.cc	2000/08/26 19:25:13	1.35
+++ prims.cc	2000/09/13 06:21:20
@@ -888,7 +888,9 @@
   main_thread->start();
   _Jv_ThreadWait ();
 
-  java::lang::Runtime::getRuntime ()->exit (0);
+  int status = (int) java::lang::ThreadGroup::had_uncaught_exception;
+    
+  java::lang::Runtime::getRuntime ()->exit (status);
 }
 
 void
@@ -939,8 +941,10 @@
       main_thread->start();
       _Jv_ThreadWait ();
     }
-  
-  java::lang::Runtime::getRuntime ()->exit (0);
+
+  int status = (int) java::lang::ThreadGroup::had_uncaught_exception;
+
+  java::lang::Runtime::getRuntime ()->exit (status);
 }
 
 
Index: java/lang/ThreadGroup.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/lang/ThreadGroup.java,v
retrieving revision 1.9
diff -u -r1.9 ThreadGroup.java
--- ThreadGroup.java	2000/06/28 06:03:11	1.9
+++ ThreadGroup.java	2000/09/13 06:21:21
@@ -53,6 +53,9 @@
 {
   /* The Initial, top-level ThreadGroup. */
   static ThreadGroup root = new ThreadGroup();
+  /* This flag is set if an uncaught exception occurs. The runtime should 
+  check this and exit with an error status if it is set. */
+  static boolean had_uncaught_exception = false;
 
   private ThreadGroup parent;
   private String name;
@@ -496,7 +499,10 @@
     if (parent != null)
       parent.uncaughtException (thread, t);
     else if (! (t instanceof ThreadDeath))
-      t.printStackTrace();
+      {
+	t.printStackTrace();
+	had_uncaught_exception = true;
+      }
   }
 
   /** Tell the VM whether it may suspend Threads in low memory

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