This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Exception and SecurityManager bits and peices
- To: java-patches at gcc dot gnu dot org
- Subject: Exception and SecurityManager bits and peices
- From: Bryce McKinlay <bryce at albatross dot co dot nz>
- Date: Mon, 12 Mar 2001 20:43:03 +1300
This patch fixes a few problems I noticed while messing around with
java.security stuff... I'm checking it in.
regards
[ bryce ]
2001-03-12 Bryce McKinlay <bryce@albatross.co.nz>
* java/lang/Runtime.java (_exit): Declare new package-private native.
* java/lang/natRuntime.cc (_exit): Implemented. Same as exit() but
without a security manager check.
(exit): Call _exit after security check.
* prims.cc (JvRunMain): Call Runtime._exit to shutdown the runtime
"naturally".
* java/lang/System.java (setSecurityManager): If a security manager
is already in place, call checkPermission.
* java/lang/ThreadGroup.java (uncaughtException): If printStackTrace()
throws an exception, try to deal with it gracefully.
* java/lang/ExceptionInInitializerError.java (printStackTrace):
Only try to print the subordinate stack trace if "exception" is set.
Print our class name first.
Index: prims.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.46
diff -u -r1.46 prims.cc
--- prims.cc 2001/01/17 08:13:06 1.46
+++ prims.cc 2001/03/12 07:09:50
@@ -850,7 +850,7 @@
int status = (int) java::lang::ThreadGroup::had_uncaught_exception;
- java::lang::Runtime::getRuntime ()->exit (status);
+ java::lang::Runtime::getRuntime ()->_exit (status);
}
void
Index: java/lang/Runtime.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Runtime.java,v
retrieving revision 1.8
diff -u -r1.8 Runtime.java
--- Runtime.java 2000/03/07 19:55:26 1.8
+++ Runtime.java 2001/03/12 07:09:50
@@ -1,6 +1,6 @@
// Runtime.java - Runtime class.
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
@@ -63,6 +63,10 @@
}
public native void exit (int status);
+
+ // Shutdown the runtime without a SecurityManager check. libgcj uses this
+ // exit function internally.
+ final native void _exit (int status);
public native long freeMemory ();
public native void gc ();
Index: java/lang/System.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/System.java,v
retrieving revision 1.7
diff -u -r1.7 System.java
--- System.java 2001/01/09 07:07:51 1.7
+++ System.java 2001/03/12 07:09:50
@@ -230,7 +230,7 @@
public static void setSecurityManager (SecurityManager s)
{
if (secman != null)
- throw new SecurityException ();
+ secman.checkPermission(new RuntimePermission("setSecurityManager"));
secman = s;
}
Index: java/lang/ThreadGroup.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/ThreadGroup.java,v
retrieving revision 1.11.4.1
diff -u -r1.11.4.1 ThreadGroup.java
--- ThreadGroup.java 2001/02/20 18:07:55 1.11.4.1
+++ ThreadGroup.java 2001/03/12 07:09:50
@@ -511,7 +511,19 @@
{
if (thread != null)
System.out.print("Exception in thread \"" + thread.getName() + "\" ");
- t.printStackTrace();
+ try
+ {
+ t.printStackTrace();
+ }
+ catch (Throwable x)
+ {
+ // This means that something is badly screwed up with the runtime,
+ // or perhaps someone is messing with the SecurityManager. In any
+ // case, try to deal with it gracefully.
+ System.out.println(t);
+ System.err.println("*** Got " + x.toString() +
+ " while trying to print stack trace");
+ }
had_uncaught_exception = true;
}
}
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.14
diff -u -r1.14 natRuntime.cc
--- natRuntime.cc 2000/09/14 07:56:28 1.14
+++ natRuntime.cc 2001/03/12 07:09:50
@@ -1,6 +1,6 @@
// natRuntime.cc - Implementation of native side of Runtime class.
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
@@ -78,7 +78,12 @@
java::lang::Runtime::exit (jint status)
{
checkExit (status);
+ _exit (status);
+}
+void
+java::lang::Runtime::_exit (jint status)
+{
// Make status right for Unix. This is perhaps strange.
if (status < 0 || status > 255)
status = 255;
Index: java/lang/ExceptionInInitializerError.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/ExceptionInInitializerError.java,v
retrieving revision 1.4
diff -u -r1.4 ExceptionInInitializerError.java
--- ExceptionInInitializerError.java 2000/11/18 02:29:13 1.4
+++ ExceptionInInitializerError.java 2001/03/12 07:09:50
@@ -1,6 +1,6 @@
// ExceptionInInitializerError.java
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
@@ -38,7 +38,7 @@
public ExceptionInInitializerError (Throwable e)
{
- super ();
+ super (e.toString());
exception = e;
}
@@ -49,17 +49,35 @@
public void printStackTrace ()
{
- exception.printStackTrace ();
+ if (exception != null)
+ {
+ System.err.print (this.getClass() + ": ");
+ exception.printStackTrace ();
+ }
+ else
+ super.printStackTrace ();
}
public void printStackTrace (PrintStream ps)
{
- exception.printStackTrace (ps);
+ if (exception != null)
+ {
+ ps.print (this.getClass() + ": ");
+ exception.printStackTrace (ps);
+ }
+ else
+ super.printStackTrace (ps);
}
public void printStackTrace (PrintWriter pw)
{
- exception.printStackTrace (pw);
+ if (exception != null)
+ {
+ pw.print (this.getClass() + ": ");
+ exception.printStackTrace (pw);
+ }
+ else
+ super.printStackTrace (pw);
}
// The exception that caused this error.