[Patch] PR libgcj/17784 - make java.lang.Thread throw SecurityException

Michael Koch konqueror@gmx.de
Thu Jan 13 10:45:00 GMT 2005


Hi list,


Our java.lang.Thread implementation doesn't throw always a
SecurityException when it needs to do so. I wrote some new mauve
testcases to check this and fixed the fails I found. Thread.enumerate()
still throws no SecurityException under some circumstances but this is
bug in java.lang.ThreadGroup. I have made a list of classes that may
throw a SecurityException (in JDK 1.4.2). I will as time alloes go
through this list and write mauve testcases to check for this and fix
the stuff we do wrong.


Ok to commit to trunk ?


Michael


2005-01-13  Michael Koch  <konqueror@gmx.de>

	PR libgcj/17784
	* java/lang/Thread.java
	(Thread): Call checkAccess().
	(stop): Fixed argument name to match javadoc.
	* java/lang/natThread.cc
	(interrupt): Call checkAccess().
	(stop): Likewise.

-------------- next part --------------
Index: java/lang/Thread.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Thread.java,v
retrieving revision 1.34
diff -u -r1.34 Thread.java
--- java/lang/Thread.java	18 Oct 2004 10:41:56 -0000	1.34
+++ java/lang/Thread.java	13 Jan 2005 10:20:31 -0000
@@ -1,5 +1,5 @@
 /* Thread -- an independent thread of executable code
-   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
+   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
    Free Software Foundation
 
 This file is part of GNU Classpath.
@@ -36,6 +36,7 @@
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package java.lang;
 
 import gnu.gcj.RawData;
@@ -321,6 +322,9 @@
 
   private Thread (Thread current, ThreadGroup g, Runnable r, String n)
   {
+    // Make sure the current thread may create a new thread.
+    checkAccess();
+    
     // The Class Libraries book says ``threadName cannot be null''.  I
     // take this to mean NullPointerException.
     if (n == null)
@@ -862,7 +866,7 @@
    * @see SecurityManager#checkPermission(Permission)
    * @deprecated unsafe operation, try not to use
    */
-  public final native void stop(Throwable e);
+  public final native void stop(Throwable t);
 
   /**
    * Suspend this Thread.  It will not come back, ever, unless it is resumed.
Index: java/lang/natThread.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natThread.cc,v
retrieving revision 1.28
diff -u -r1.28 natThread.cc
--- java/lang/natThread.cc	11 Sep 2004 19:10:44 -0000	1.28
+++ java/lang/natThread.cc	13 Jan 2005 10:20:31 -0000
@@ -112,6 +112,7 @@
 void
 java::lang::Thread::interrupt (void)
 {
+  checkAccess ();
   natThread *nt = (natThread *) data;
   _Jv_ThreadInterrupt (nt->thread);
 }
@@ -321,6 +322,7 @@
 void
 java::lang::Thread::stop (java::lang::Throwable *)
 {
+  checkAccess ();
   throw new UnsupportedOperationException
     (JvNewStringLatin1 ("Thread.stop unimplemented"));
 }


More information about the Java-patches mailing list