[cp-patches] RFC: fix for PR 24642

2006-04-12 Thread Casey Marshall
This patch implements seeding of all SecureRandom instances if you  
call `nextBytes' without providing a seed yourself, and provides a  
better implementation of the static `getSeed' method.


This introduces a new VM class, `java.security.VMSecureRandom,' that  
contains a single static method for generating real (or close to  
real) random seed values. The default implementation uses a set of  
eight "dueling" threads, each of which increments a counter in a  
tight loop. These eight counters are XORed together to produce a  
single random byte. The idea is that thread scheduling decisions are  
hard to predict, and thus that the values of these eight counters is  
hard to guess. This isn't generally true, but seems to work OK on  
some systems. It's also inefficient, but doesn't seem to bad, even on  
JamVM, since it is used sparingly.


Getting a seed value does the following:

  1. Try to read from the URL given in the security property  
`securerandom.seed.'
  2. If that property is not set, or is set to a malformed URL, try  
to read from the URL given by the system property `java.security.egd.'
  3. If neither property is set to a valid URL, or if reading that  
URL fails, call `VMSecureRandom.generateSeed.'


The thing to do on most Unix systems is to point the  
`securerandom.source' property to `file:/dev/random' or `file:/dev/ 
urandom.'


Does this look OK?

Index: java/security/SecureRandom.java
===
RCS file: /cvsroot/classpath/classpath/java/security/SecureRandom.java,v
retrieving revision 1.20
diff -u -b -B -r1.20 SecureRandom.java
--- java/security/SecureRandom.java 26 Feb 2006 04:49:18 -  1.20
+++ java/security/SecureRandom.java 13 Apr 2006 04:59:03 -
@@ -1,5 +1,5 @@
 /* SecureRandom.java --- Secure Random class implementation
-   Copyright (C) 1999, 2001, 2002, 2003, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2002, 2003, 2005, 2006  Free Software Foundation, 
Inc.
 
 This file is part of GNU Classpath.
 
@@ -37,11 +37,19 @@
 
 package java.security;
 
+import gnu.classpath.SystemProperties;
 import gnu.java.security.Engine;
+import gnu.java.security.action.GetSecurityPropertyAction;
 import gnu.java.security.jce.prng.Sha160RandomSpi;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Enumeration;
 import java.util.Random;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * An interface to a cryptographically secure pseudo-random number
@@ -72,6 +80,8 @@
   SecureRandomSpi secureRandomSpi = null;
   byte[] state = null;
 
+  private boolean isSeeded = false;
+
   // Constructors.
   // 
 
@@ -277,6 +287,7 @@
   public void setSeed(byte[] seed)
   {
 secureRandomSpi.engineSetSeed(seed);
+isSeeded = true;
   }
 
   /**
@@ -304,6 +315,7 @@
   (byte) (0xff & seed)
 };
 secureRandomSpi.engineSetSeed(tmp);
+isSeeded = true;
   }
   }
 
@@ -315,6 +327,10 @@
*/
   public void nextBytes(byte[] bytes)
   {
+if (!isSeeded)
+  {
+setSeed (getSeed (32));
+  }
 randomBytesUsed += bytes.length;
 counter++;
 secureRandomSpi.engineNextBytes(bytes);
@@ -360,10 +376,8 @@
   public static byte[] getSeed(int numBytes)
   {
 byte[] tmp = new byte[numBytes];
-
-new Random().nextBytes(tmp);
+generateSeed (tmp);
 return tmp;
-//return secureRandomSpi.engineGenerateSeed( numBytes );
   }
 
   /**
@@ -378,4 +392,64 @@
 return secureRandomSpi.engineGenerateSeed(numBytes);
   }
 
+  // Seed methods.
+
+  private static final String SECURERANDOM_SOURCE = "securerandom.source";
+  private static final String JAVA_SECURITY_EGD = "java.security.egd";
+  private static final Logger logger = Logger.getLogger 
(SecureRandom.class.getName ());
+
+  private static int generateSeed (byte[] buffer)
+  {
+return generateSeed (buffer, 0, buffer.length);
+  }
+
+  private static int generateSeed (byte[] buffer, int offset, int length)
+  {
+URL sourceUrl = null;
+String urlStr = null;
+
+GetSecurityPropertyAction action = new GetSecurityPropertyAction 
(SECURERANDOM_SOURCE);
+try
+  {
+urlStr = (String) AccessController.doPrivileged (action);
+if (urlStr != null)
+  sourceUrl = new URL (urlStr);
+  }
+catch (MalformedURLException ignored)
+  {
+logger.log (Level.WARNING, SECURERANDOM_SOURCE + " property is 
malformed: {0}", 
+urlStr);
+  }
+
+if (sourceUrl == null)
+  {
+try
+  {
+urlStr = SystemProperties.getProperty (JAVA_SECURITY_EGD);
+if (urlStr != null)
+  sourceUrl = new URL (urlStr);
+  }
+catch (MalformedURLException mue)
+  {
+logge

Re: [cp-patches] RFC: local (unix-domain) sockets

2006-04-12 Thread Thomas Fitzsimmons
Hi,

On Wed, 2006-04-12 at 18:11 -0700, Casey Marshall wrote:

> Note that this patch has to be cleaned up a lot, mostly to add  
> detection for local socket support in configure. Also, SocketChannel  
> support is missing, but may not be too hard to implement.
> 
> If there is interest, I can polish this up some more and check it in.

That would be great.  Java DBUS bindings will require this, so will the
X protocol peer set we discussed on IRC.

Tom





[cp-patches] RFC: local (unix-domain) sockets

2006-04-12 Thread Casey Marshall

Hi.

A few of us were chatting in IRC today about local socket support,  
aka Unix domain sockets, in Classpath (that is, where you bind a  
socket to a special file, instead of to a network address. This is  
used mostly for IPC; for example, local X11 connections can use local  
sockets). I mentioned that I had written such a thing, and some  
people were interested in seeing this in Classpath.


So, do we want this? The attached patch is my implementation of this,  
which basically introduces three new classes:


  gnu.java.net.local.LocalServerSocket
  gnu.java.net.local.LocalSocket
  gnu.java.net.local.LocalSocketAddress

Which operate similarly to how normal Sockets do, but over local  
sockets.


Note that this patch has to be cleaned up a lot, mostly to add  
detection for local socket support in configure. Also, SocketChannel  
support is missing, but may not be too hard to implement.


If there is interest, I can polish this up some more and check it in.

Thanks.

--- /dev/null   2006-04-12 17:45:39.0 -0700
+++ include/gnu_java_net_local_LocalSocketImpl.h2006-04-12 
16:41:25.0 -0700
@@ -0,0 +1,31 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+
+#ifndef __gnu_java_net_local_LocalSocketImpl__
+#define __gnu_java_net_local_LocalSocketImpl__
+
+#include 
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_create (JNIEnv 
*env, jobject, jboolean);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_listen (JNIEnv 
*env, jobject, jint);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_accept (JNIEnv 
*env, jobject, jobject);
+JNIEXPORT jint JNICALL Java_gnu_java_net_local_LocalSocketImpl_available 
(JNIEnv *env, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_close (JNIEnv 
*env, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_sendUrgentData 
(JNIEnv *env, jobject, jint);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_shutdownInput 
(JNIEnv *env, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_shutdownOutput 
(JNIEnv *env, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_unlink (JNIEnv 
*env, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_localBind 
(JNIEnv *env, jobject, jobject);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_localConnect 
(JNIEnv *env, jobject, jobject);
+JNIEXPORT jint JNICALL Java_gnu_java_net_local_LocalSocketImpl_read (JNIEnv 
*env, jobject, jbyteArray, jint, jint);
+JNIEXPORT void JNICALL Java_gnu_java_net_local_LocalSocketImpl_write (JNIEnv 
*env, jobject, jbyteArray, jint, jint);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __gnu_java_net_local_LocalSocketImpl__ */
--- /dev/null   2006-04-12 17:45:39.0 -0700
+++ gnu/java/net/local/LocalServerSocket.java   2006-04-12 15:21:42.0 
-0700
@@ -0,0 +1,172 @@
+/* LocalServerSocket.java -- a unix domain server socket.
+   Copyright (C) 2006  Free Software Foundation, Inc.
+
+This file is a part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or (at
+your option) any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
+USA
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version.  */
+
+
+package gnu.java.net.local;
+
+import java.io.IOException;
+
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+
+

[cp-patches] FYI: InternalFrameEvent.paramString() implemented

2006-04-12 Thread David Gilbert
This patch (committed) implements the paramString() method in the InternalFrameEvent 
class.  This method is used as an input into the toString() method, primarily to 
provide useful information in debugging output.  I also tidied up the API docs a little.


2006-04-12  David Gilbert  <[EMAIL PROTECTED]>

* javax/swing/event/InternalFrameEvent.java:
(paramString): Implemented,
updated API docs all over.

Regards,

Dave
Index: javax/swing/event/InternalFrameEvent.java
===
RCS file: 
/sources/classpath/classpath/javax/swing/event/InternalFrameEvent.java,v
retrieving revision 1.9
diff -u -r1.9 InternalFrameEvent.java
--- javax/swing/event/InternalFrameEvent.java   2 Jul 2005 20:32:50 -   
1.9
+++ javax/swing/event/InternalFrameEvent.java   12 Apr 2006 21:25:36 -
@@ -1,5 +1,5 @@
 /* InternalFrameEvent.java --
-   Copyright (C) 2002, 2004  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2006,  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -43,6 +43,8 @@
 import javax.swing.JInternalFrame;
 
 /**
+ * An event that indicates a change to a [EMAIL PROTECTED] JInternalFrame} 
component.
+ * 
  * @author Andrew Selkirk
  */
 public class InternalFrameEvent extends AWTEvent
@@ -50,55 +52,59 @@
   private static final long serialVersionUID = -5204823611874873183L;
 
   /**
-   * Internal frame activated event
+   * Internal frame activated event.
*/
   public static final int INTERNAL_FRAME_ACTIVATED = 25554;
 
   /**
-   * Internal frame closed event
+   * Internal frame closed event.
*/
   public static final int INTERNAL_FRAME_CLOSED = 25551;
 
   /**
-   * Internal frame closing event
+   * Internal frame closing event.
*/
   public static final int INTERNAL_FRAME_CLOSING = 25550;
 
   /**
-   * Internal frame deactivated event
+   * Internal frame deactivated event.
*/
   public static final int INTERNAL_FRAME_DEACTIVATED = 2;
 
   /**
-   * Internal frame deiconifed event
+   * Internal frame deiconifed event.
*/
   public static final int INTERNAL_FRAME_DEICONIFIED = 25553;
 
   /**
-   * Internal frame frame first event
+   * Internal frame frame first event.
*/
   public static final int INTERNAL_FRAME_FIRST = 25549;
 
   /**
-   * Internal frame iconified event
+   * Internal frame iconified event.
*/
   public static final int INTERNAL_FRAME_ICONIFIED = 25552;
 
   /**
-   * Internal frame last event
+   * Internal frame last event.
*/
   public static final int INTERNAL_FRAME_LAST = 2;
 
   /**
-   * Internal frame opened event
+   * Internal frame opened event.
*/
   public static final int INTERNAL_FRAME_OPENED = 25549;
 
   /**
-   * Creates a JInternalFrameEvent object.
+   * Creates a new JInternalFrameEvent instance.
* 
-   * @param source The source of this event.
-   * @param id Then event ID of this event.
+   * @param source  the source of this event (null not permitted).
+   * @param id  the event ID of this event (see the constants defined by this
+   * class).
+   * 
+   * @throws IllegalArgumentException if source is 
+   * null.
*/
   public InternalFrameEvent(JInternalFrame source, int id)
   {
@@ -106,10 +112,43 @@
   }
 
   /**
-   * Returns the JInternalFrame object stored in this event.
+   * Returns the JInternalFrame component that is the source for
+   * this event.
+   * 
+   * @return The source.
+   * 
+   * @since 1.3
*/
   public JInternalFrame getInternalFrame()
   {
 return (JInternalFrame) source;
   }
+  
+  /**
+   * Returns a string that indicates the event id.  This is used by the 
+   * [EMAIL PROTECTED] #toString()} method.
+   * 
+   * @return A string that indicates the event id.
+   */
+  public String paramString() 
+  {
+switch (id) {
+  case INTERNAL_FRAME_ACTIVATED:
+return "INTERNAL_FRAME_ACTIVATED";
+  case INTERNAL_FRAME_CLOSED:
+return "INTERNAL_FRAME_CLOSED";
+  case INTERNAL_FRAME_CLOSING:
+return "INTERNAL_FRAME_CLOSING";
+  case INTERNAL_FRAME_DEACTIVATED:
+return "INTERNAL_FRAME_DEACTIVATED";
+  case INTERNAL_FRAME_DEICONIFIED:
+return "INTERNAL_FRAME_DEICONIFIED";
+  case INTERNAL_FRAME_ICONIFIED:
+return "INTERNAL_FRAME_ICONIFIED";
+  case INTERNAL_FRAME_OPENED:
+return "INTERNAL_FRAME_OPENED";
+  default:
+return "unknown type";
+}
+  }
 }


[cp-patches] PATCH: fix Fortuna

2006-04-12 Thread Casey Marshall

Hi.

I was playing with the Fortuna PRNG a little, and found a bug where  
it would not initialize its block when `setup' is called (the  
Generator PRNG also has this problem). As a consequence, the first  
block you get out of the PRNG is all zeros. This patch fixes that  
problem.


2006-04-12  Casey Marshall  <[EMAIL PROTECTED]>

* gnu/javax/crypto/prng/Fortuna.java (setup): call `fillBlock.'
(Generator.setup): call `fillBlock.'

Committed.

Index: gnu/javax/crypto/prng/Fortuna.java
===
RCS file: /cvsroot/classpath/classpath/gnu/javax/crypto/prng/Fortuna.java,v
retrieving revision 1.1
diff -u -B -b -r1.1 Fortuna.java
--- gnu/javax/crypto/prng/Fortuna.java  26 Jan 2006 02:25:09 -  1.1
+++ gnu/javax/crypto/prng/Fortuna.java  12 Apr 2006 18:00:39 -
@@ -142,6 +142,14 @@
 pool = 0;
 pool0Count = 0;
 generator.init(attributes);
+try
+  {
+fillBlock ();
+  }
+catch (LimitReachedException shouldNotHappen)
+  {
+throw new RuntimeException (shouldNotHappen);
+  }
   }
 
   public void fillBlock() throws LimitReachedException
@@ -324,6 +332,7 @@
   byte[] seed = (byte[]) attributes.get(SEED);
   if (seed != null)
 addRandomBytes(seed);
+  fillBlock ();
 }
 
 /**


[cp-patches] FYI: fix for PR classpath/24481

2006-04-12 Thread Casey Marshall

Hi.

This patch is an attempt to fix bug 24481, which has to do with  
issues setting seed values for SecureRandom implementations. It does  
this by updating the message digest with the seed; I don't know if  
this is the "correct" way to augment a MD-based PRNG, but it seems  
like it should be safe.


2006-04-12  Casey Marshall  <[EMAIL PROTECTED]>

Fixes PR classpath/24481.
* gnu/java/security/jce/prng/SecureRandomAdapter.java ():
initialize the adaptee.
(setSeed): call `addRandomBytes;' don't re-initialize the adaptee.
* gnu/java/security/prng/MDGenerator.java (addRandomByte,
addRandomBytes): new methods.

Committed.

Index: gnu/java/security/prng/MDGenerator.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/security/prng/MDGenerator.java,v
retrieving revision 1.2
diff -u -B -b -r1.2 MDGenerator.java
--- gnu/java/security/prng/MDGenerator.java 24 Feb 2006 11:14:23 -  
1.2
+++ gnu/java/security/prng/MDGenerator.java 12 Apr 2006 05:12:53 -
@@ -122,6 +122,20 @@
 md.update(buffer, 0, buffer.length);
   }
 
+  public void addRandomByte (final byte b)
+  {
+if (md == null)
+  throw new IllegalStateException ("not initialized");
+md.update (b);
+  }
+
+  public void addRandomBytes (final byte[] buf, final int off, final int len)
+  {
+if (md == null)
+  throw new IllegalStateException ("not initialized");
+md.update (buf, off, len);
+  }
+
   // Cloneable interface implementation ---
 
   public Object clone() throws CloneNotSupportedException
Index: gnu/java/security/jce/prng/SecureRandomAdapter.java
===
RCS file: 
/cvsroot/classpath/classpath/gnu/java/security/jce/prng/SecureRandomAdapter.java,v
retrieving revision 1.1
diff -u -B -b -r1.1 SecureRandomAdapter.java
--- gnu/java/security/jce/prng/SecureRandomAdapter.java 26 Jan 2006 02:25:10 
-  1.1
+++ gnu/java/security/jce/prng/SecureRandomAdapter.java 12 Apr 2006 05:12:53 
-
@@ -42,7 +42,7 @@
 import gnu.java.security.prng.MDGenerator;
 
 import java.security.SecureRandomSpi;
-import java.util.HashMap;
+import java.util.Collections;
 
 /**
  * The implementation of a generic [EMAIL PROTECTED] 
java.security.SecureRandom} adapter
@@ -80,6 +80,7 @@
 super();
 
 this.mdName = mdName;
+adaptee.init (Collections.singletonMap (MDGenerator.MD_NAME, mdName));
   }
 
   // Class methods
@@ -118,9 +119,6 @@
 
   public void engineSetSeed(byte[] seed)
   {
-HashMap attributes = new HashMap();
-attributes.put(MDGenerator.MD_NAME, mdName);
-attributes.put(MDGenerator.SEEED, seed);
-adaptee.init(attributes);
+adaptee.addRandomBytes (seed);
   }
 }


Re: [cp-patches] FYI: Improve DataOutputStream.writeUTF()

2006-04-12 Thread Tom Tromey
> "Mark" == Mark Wielaard <[EMAIL PROTECTED]> writes:

Mark> FAIL: gnu.testlet.java.io.ObjectInputOutput.OutputTest: Serializable:
Mark> gnu.testlet.java.io.ObjectInputOutput.Test$Extern () (number 2)
Mark> FAIL: gnu.testlet.java.text.DecimalFormatSymbols.serial (number 1)

The new code wasn't handling zero length strings properly.
I'm checking this in.

Tom

2006-04-12  Tom Tromey  <[EMAIL PROTECTED]>

* java/io/DataOutputStream.java (writeUTF): Correctly handle zero
length strings.

Index: java/io/DataOutputStream.java
===
RCS file: /cvsroot/classpath/classpath/java/io/DataOutputStream.java,v
retrieving revision 1.22
diff -u -r1.22 DataOutputStream.java
--- java/io/DataOutputStream.java   11 Apr 2006 19:10:59 -  1.22
+++ java/io/DataOutputStream.java   12 Apr 2006 16:16:18 -
@@ -450,7 +450,7 @@
 if (buf == null)
   buf = new byte[512];
 
-while (i < len)
+do
   {
while (i < len && pos < buf.length - 3)
  {
@@ -483,6 +483,7 @@
write(buf, 0, pos);
pos = 0;
  }
+while (i < len);
   }
 
 } // class DataOutputStream



Re: [cp-patches] FYI: Merge Thread.UncaughtExceptionHandler support from generics branch

2006-04-12 Thread Mark Wielaard
Hi Archie,

On Wed, 2006-04-12 at 09:10 -0500, Archie Cobbs wrote:
> Mark Wielaard wrote:
> > +  /** 
> > +   * 
> > +   * Returns the handler used when this thread terminates due to an
> > +   * uncaught exception.  The handler used is determined by the following:
> > +   * 
> > +   * 
> > +   * If this thread has its own handler, this is returned.
> > +   * If not, then the handler of the thread's ThreadGroup
> > +   * object is returned.
> > +   * If both are unavailable, then null is returned.
> > +   * 
> > +   * 
> > +   * @return the appropriate UncaughtExceptionHandler or
> > +   * null if one can't be obtained.
> > +   * @since 1.5 
> > +   */
> > +  public UncaughtExceptionHandler getUncaughtExceptionHandler()
> > +  {
> > +return exceptionHandler;
> > +  }
> 
> The Javadoc and the implementation here don't seem consistent: how
> could this ever return the thread's ThreadGroup (option #2)?

Good catch. The documentation describes how VMThread handles this. But
it looks like we can simplify that code by just doing it here as the
documentation says.

Andrew/Tom, you wrote/documented that code what do you think of this
patch?

2006-04-12  Mark Wielaard  <[EMAIL PROTECTED]>

* java/lang/Thread.java (getUncaughtExceptionHandler): Return
thread group when exceptionHandler isn't set.
* vm/reference/java/lang/VMThread.java (run): Use result of
thread.getUncaughtExceptionHandler directly.

Cheers,

Mark
Index: java/lang/Thread.java
===
RCS file: /cvsroot/classpath/classpath/java/lang/Thread.java,v
retrieving revision 1.19
diff -u -r1.19 Thread.java
--- java/lang/Thread.java	12 Apr 2006 12:04:18 -	1.19
+++ java/lang/Thread.java	12 Apr 2006 16:08:50 -
@@ -1051,7 +1051,9 @@
* If this thread has its own handler, this is returned.
* If not, then the handler of the thread's ThreadGroup
* object is returned.
-   * If both are unavailable, then null is returned.
+   * If both are unavailable, then null is returned
+   * (which can only happen when the thread was terminated since
+   *  then it won't have an associated thread group anymore).
* 
* 
* @return the appropriate UncaughtExceptionHandler or
@@ -1060,7 +1062,7 @@
*/
   public UncaughtExceptionHandler getUncaughtExceptionHandler()
   {
-return exceptionHandler;
+return exceptionHandler != null : exceptionHandler ? group;
   }
 
   /** 
Index: vm/reference/java/lang/VMThread.java
===
RCS file: /cvsroot/classpath/classpath/vm/reference/java/lang/VMThread.java,v
retrieving revision 1.10
diff -u -r1.10 VMThread.java
--- vm/reference/java/lang/VMThread.java	12 Apr 2006 12:04:18 -	1.10
+++ vm/reference/java/lang/VMThread.java	12 Apr 2006 16:08:50 -
@@ -1,5 +1,5 @@
 /* VMThread -- VM interface for Thread of executable code
-   Copyright (C) 2003, 2004, 2005 Free Software Foundation
+   Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -123,9 +123,8 @@
 	{
 		try
 		{
-		  Thread.UncaughtExceptionHandler handler = thread.getUncaughtExceptionHandler();
-		  if (handler == null)
-		handler = thread.group;
+		  Thread.UncaughtExceptionHandler handler;
+		  handler = thread.getUncaughtExceptionHandler();
 		  handler.uncaughtException(thread, t);
 		}
 		catch(Throwable ignore)


signature.asc
Description: This is a digitally signed message part


Re: [cp-patches] FYI: gnu.xml.dom.html2.* fixes and additions

2006-04-12 Thread Lillian Angel
More bug fixes for the parser and related classes.

2006-04-12  Lillian Angel  <[EMAIL PROTECTED]>

* gnu/xml/dom/DomDocument.java
(checkNCName): Removed unneeded part of check.
* gnu/xml/dom/DomNode.java
(dispatchEvent): Added code to grow ancestors array
if needed. Changed checks to use depth of node instead.
Fixes an infinite loop and segmentation fault.
* gnu/xml/dom/html2/DomHTMLParser.java
(handleEndTag): No need to use/make a copy of the node.
Causes an infinite loop.



On Tue, 2006-04-11 at 14:07 -0400, Lillian Angel wrote:
> I have changed gcjwebplugin to use the parser in 
> gnu/xml/dom/html2/*.
> 
> I added some needed functions/classes. Also, fixed a few minor bugs in
> the parser and awt.
> 
> 2006-04-11  Lillian Angel  <[EMAIL PROTECTED]>
> 
> * gnu/xml/dom/DomNodeIterator.java
> (nextNode): Moved line of code to avoid an infinite loop.
> * gnu/xml/dom/html2/DomHTMLAppletElement.java
> (getCls): New function.
> (setCls): Likewise.
> (getSrc): Likewise.
> (setSrc): Likewise.
> * gnu/xml/dom/html2/DomHTMLDocument.java:
> Added DomHTMLEmbedElement to map.
> (getApplets): Added node name, 'embed'.
> * gnu/xml/dom/html2/DomHTMLEmbedElement.java:
> New class.
> * gnu/xml/dom/html2/DomHTMLObjectElement.java
> (getJavaCode): New function.
> (setJavaCode): Likewise.
> (getObject): Likewise.
> (setObject): Likewise.
> (getJavaObject): Likewise.
> (setJavaObject): Likewise.
> (getJavaArchive): Likewise.
> (setJavaArchive): Likewise.
> (getJavaCodeBase): Likewise.
> (setJavaCodeBase): Likewise.
> (getJavaType): Likewise.
> (setJavaType): Likewise.
> (setMayscript): Likewise.
> (getMayscript): Likewise.
> (setScriptable): Likewise.
> (getScriptable): Likewise.
> * gnu/xml/dom/html2/DomHTMLParser.java
> (parseDocument): Should not check for well formedness
> when parsing an html document.
> * java/awt/Window.java
> (dispatchEvent): Added check to avoid NPE.
> 
Index: gnu/xml/dom/DomDocument.java
===
RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/DomDocument.java,v
retrieving revision 1.8
diff -u -r1.8 DomDocument.java
--- gnu/xml/dom/DomDocument.java	12 Jan 2006 16:35:52 -	1.8
+++ gnu/xml/dom/DomDocument.java	12 Apr 2006 16:04:42 -
@@ -535,8 +535,7 @@
 int index = name.indexOf(':');
 if (index != -1)
   {
-if (index == 0 || index == (len - 1) ||
-name.lastIndexOf(':') != index)
+if (index == 0 || name.lastIndexOf(':') != index)
   {
 throw new DomDOMException(DOMException.NAMESPACE_ERR,
   name, null, 0);
Index: gnu/xml/dom/DomNode.java
===
RCS file: /cvsroot/classpath/classpath/gnu/xml/dom/DomNode.java,v
retrieving revision 1.13
diff -u -r1.13 DomNode.java
--- gnu/xml/dom/DomNode.java	12 Jan 2006 19:46:59 -	1.13
+++ gnu/xml/dom/DomNode.java	12 Apr 2006 16:04:42 -
@@ -1120,7 +1120,6 @@
 node.appendChild(newChild);
   }
   }
-
 if (nodeType == ENTITY_REFERENCE_NODE)
   {
 node.makeReadonly();
@@ -1556,23 +1555,30 @@
 ancestorLen = ancestors.length;
   }
 
-// XXX autogrow ancestors ... based on statistics
-
 // Climb to the top of this subtree and handle capture, letting
 // each node (from the top down) capture until one stops it or
 // until we get to this one.
-
-for (index = 0, current = parent;
- current != null && index < ancestorLen;
- index++, current = current.parent)
+current = parent;
+if (current.depth >= ANCESTORS_INIT)
+  {
+DomNode[] newants = new DomNode[current.depth + 1];
+System.arraycopy(ancestors, 0, newants, 0, ancestors.length);
+ancestors = newants;
+ancestorLen = ancestors.length;
+  }
+for (index = 0; index < ancestorLen; index++)
   {
+if (current == null || current.depth == 0)
+  break;
+
 if (current.nListeners != 0)
   {
 haveAncestorRegistrations = true;
   }
 ancestors [index] = current;
+current = current.parent;
   }
-if (current != null)
+if (current.depth > 0)
   {
 throw new RuntimeException("dispatchEvent capture stack size");
   }
Index: gnu/xml/dom/html2/DomHTMLParser.java
===
RCS file: /cvsroot/classpath/classpath/gnu/xml/

[cp-patches] Patch: FYI: PR 27131

2006-04-12 Thread Tom Tromey
I'm checking this in.

This fixes PR 27131.  David already checked in a Mauve test for this.

Tom

2006-04-12  Tom Tromey  <[EMAIL PROTECTED]>

PR classpath/27131:
* java/util/BitSet.java (get): Early return if to==from.

Index: java/util/BitSet.java
===
RCS file: /cvsroot/classpath/classpath/java/util/BitSet.java,v
retrieving revision 1.19
diff -u -r1.19 BitSet.java
--- java/util/BitSet.java   5 Jul 2005 10:28:03 -   1.19
+++ java/util/BitSet.java   12 Apr 2006 16:00:37 -
@@ -365,7 +365,7 @@
   throw new IndexOutOfBoundsException();
 BitSet bs = new BitSet(to - from);
 int lo_offset = from >>> 6;
-if (lo_offset >= bits.length)
+if (lo_offset >= bits.length || to == from)
   return bs;
 
 int lo_bit = from & LONG_MASK;



Re: [cp-patches] FYI: Merge Thread.UncaughtExceptionHandler support from generics branch

2006-04-12 Thread Archie Cobbs

Mark Wielaard wrote:
+  /** 
+   * 

+   * Returns the handler used when this thread terminates due to an
+   * uncaught exception.  The handler used is determined by the following:
+   * 
+   * 
+   * If this thread has its own handler, this is returned.
+   * If not, then the handler of the thread's ThreadGroup
+   * object is returned.
+   * If both are unavailable, then null is returned.
+   * 
+   * 
+   * @return the appropriate UncaughtExceptionHandler or

+   * null if one can't be obtained.
+   * @since 1.5 
+   */

+  public UncaughtExceptionHandler getUncaughtExceptionHandler()
+  {
+return exceptionHandler;
+  }


The Javadoc and the implementation here don't seem consistent: how
could this ever return the thread's ThreadGroup (option #2)?

-Archie

__
Archie Cobbs  *CTO, Awarix*  http://www.awarix.com



[cp-patches] FYI: Implement SecureRandom.getAlgorithm()

2006-04-12 Thread Mark Wielaard
Hi,

While investigating a SecureRandom bug (which is being handled by Casey
now) I was surprized to see there was no getAlgorithm() method. As it
happens there should be one, but we just didn't have it yet. So here is
it:

2006-04-12  Mark Wielaard  <[EMAIL PROTECTED]>

* java/security/SecureRandom.java (algorithm): New private field.
(SecureRandom): Initialize algorithm.
(SecureRandom(SecureRandomSpi,Provider,String)): New private
constructor.
(getInstance): Call 3 argument constructor.
(getAlgorithm): New method.

Committed,

Mark
Index: java/security/SecureRandom.java
===
RCS file: /cvsroot/classpath/classpath/java/security/SecureRandom.java,v
retrieving revision 1.20
diff -u -r1.20 SecureRandom.java
--- java/security/SecureRandom.java	26 Feb 2006 04:49:18 -	1.20
+++ java/security/SecureRandom.java	12 Apr 2006 12:49:12 -
@@ -1,5 +1,6 @@
 /* SecureRandom.java --- Secure Random class implementation
-   Copyright (C) 1999, 2001, 2002, 2003, 2005  Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001, 2002, 2003, 2005, 2006
+   Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -71,6 +72,7 @@
   int randomBytesUsed = 0;
   SecureRandomSpi secureRandomSpi = null;
   byte[] state = null;
+  private String algorithm;
 
   // Constructors.
   // 
@@ -111,6 +113,7 @@
 secureRandomSpi = (SecureRandomSpi) Class.
   forName(classname).newInstance();
 provider = p[i];
+algorithm = key.substring(13); // Minus SecureRandom.
 return;
   }
 catch (ThreadDeath death)
@@ -128,6 +131,7 @@
 
 // Nothing found. Fall back to SHA1PRNG
 secureRandomSpi = new Sha160RandomSpi();
+algorithm = "Sha160";
   }
 
   /**
@@ -159,8 +163,18 @@
*/
   protected SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider)
   {
+this(secureRandomSpi, provider, "unknown");
+  }
+
+  /**
+   * Private constructor called from the getInstance() method.
+   */
+  private SecureRandom(SecureRandomSpi secureRandomSpi, Provider provider,
+		   String algorithm)
+  {
 this.secureRandomSpi = secureRandomSpi;
 this.provider = provider;
+this.algorithm = algorithm;
   }
 
   // Class methods.
@@ -243,7 +257,7 @@
   {
 return new SecureRandom((SecureRandomSpi)
   Engine.getInstance(SECURE_RANDOM, algorithm, provider),
-  provider);
+  provider, algorithm);
   }
 catch (java.lang.reflect.InvocationTargetException ite)
   {
@@ -269,6 +283,18 @@
   }
 
   /**
+   * Returns the algorithm name used or "unknown" when the algorithm
+   * used couldn't be determined (as when constructed by the protected
+   * 2 argument constructor).
+   *
+   * @since 1.5
+   */
+  public String getAlgorithm()
+  {
+return algorithm;
+  }
+
+  /**
  Seeds the SecureRandom. The class is re-seeded for each call and 
  each seed builds on the previous seed so as not to weaken security.
 


signature.asc
Description: This is a digitally signed message part


[cp-patches] FYI: Merge Thread.UncaughtExceptionHandler support from generics branch

2006-04-12 Thread Mark Wielaard
Hi,

One of the Debian package maintainers requested that the
Thread.UncaughtExceptionHandler support would be added to head since it
isn't dependent on any new language features. This patch does so and
documents the VMThread change needed for this in the NEWS file.

The remaining diff between the head and generics Thread file is a new
Enum and some indentation changes.

2006-04-12  Mark Wielaard  <[EMAIL PROTECTED]>

Port UncaughtExceptionHandler support from generics branch.
* NEWS: Document Thread.UncaughtExceptionHandler VMThread change.

2006-04-12  Andrew John Hughes  <[EMAIL PROTECTED]>

* java/lang/Thread.java:
(setUncaughtExceptionHandler(UncaughtExceptionHandler):
Added docs and security check.
(getUncaughtExceptionHandler()): Documented.
(setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler):
Added docs and security check.
(getDefaultUncaughtExceptionHandler()): Documented.
(getId()): Documented.

2006-04-12  Tom Tromey  <[EMAIL PROTECTED]>

* vm/reference/java/lang/VMThread.java (run): Use thread's
uncaught handler.
* java/lang/Thread.java (defaultHandler): New field.
(setDefaultUncaughtExceptionHandler,
getDefaultUncaughtExceptionHandler, setUncaughtExceptionHandler,
getUncaughtExceptionHandler): New methods.
* java/lang/ThreadGroup.java (ThreadGroup): Implements
UncaughtExceptionHandler.
(uncaughtException): Use getDefaultUncaughtExceptionHandler.

Committed,

Mark
Index: NEWS
===
RCS file: /cvsroot/classpath/classpath/NEWS,v
retrieving revision 1.130
diff -u -r1.130 NEWS
--- NEWS	29 Mar 2006 13:10:11 -	1.130
+++ NEWS	12 Apr 2006 11:52:52 -
@@ -29,6 +29,8 @@
   now have a new native getModifiersInternal() method.  The public
   getModifiers() method in each case has been rewritten in terms of
   this method.
+* The reference implementation of VMThread has been updated to handle
+  the new Thread.UncaughtExceptionHandler support.
 
 New in release 0.90 (March 6, 2006)
 
Index: java/lang/Thread.java
===
RCS file: /cvsroot/classpath/classpath/java/lang/Thread.java,v
retrieving revision 1.18
diff -u -r1.18 Thread.java
--- java/lang/Thread.java	16 Feb 2006 09:53:13 -	1.18
+++ java/lang/Thread.java	12 Apr 2006 11:52:52 -
@@ -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, 2006
Free Software Foundation
 
 This file is part of GNU Classpath.
@@ -81,6 +81,7 @@
  * @author Tom Tromey
  * @author John Keiser
  * @author Eric Blake ([EMAIL PROTECTED])
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
  * @see Runnable
  * @see Runtime#exit(int)
  * @see #run()
@@ -130,15 +131,27 @@
 
   /** The context classloader for this Thread. */
   private ClassLoader contextClassLoader;
+  
+  /** This thread's ID.  */
+  private final long threadId;
 
   /** The next thread number to use. */
   private static int numAnonymousThreadsCreated;
+  
+  /** The next thread ID to use.  */
+  private static long nextThreadId;
+
+  /** The default exception handler.  */
+  private static UncaughtExceptionHandler defaultHandler;
 
   /** Thread local storage. Package accessible for use by
 * InheritableThreadLocal.
 */
   WeakIdentityHashMap locals;
 
+  /** The uncaught exception handler.  */
+  UncaughtExceptionHandler exceptionHandler;
+
   /**
* Allocates a new Thread object. This constructor has
* the same effect as Thread(null, null,
@@ -342,6 +355,11 @@
 this.name = name.toString();
 this.runnable = target;
 this.stacksize = size;
+
+synchronized (Thread.class)
+  {
+this.threadId = nextThreadId++;
+  }
 
 priority = current.priority;
 daemon = current.daemon;
@@ -371,6 +389,11 @@
 this.priority = priority;
 this.daemon = daemon;
 this.contextClassLoader = ClassLoader.getSystemClassLoader();
+synchronized (Thread.class)
+  {
+	this.threadId = nextThreadId++;
+  }
+
   }
 
   /**
@@ -1000,4 +1023,157 @@
   }
 return locals;
   }
+
+  /** 
+   * Assigns the given UncaughtExceptionHandler to this
+   * thread.  This will then be called if the thread terminates due
+   * to an uncaught exception, pre-empting that of the
+   * ThreadGroup.
+   *
+   * @param h the handler to use for this thread.
+   * @throws SecurityException if the current thread can't modify this thread.
+   * @since 1.5 
+   */
+  public void setUncaughtExceptionHandler(UncaughtExceptionHandler h)
+  {
+SecurityManager sm = SecurityManager.current; // Be thread-safe.
+if (sm != null)
+  sm.checkAccess(this);
+exceptionHandler = h;
+  }
+
+  /** 
+   * 
+   * Returns the handler used when this thread terminates due to an
+   * uncaught exception.  The handler used is determ

Re: [cp-patches] FYI: Improve DataOutputStream.writeUTF()

2006-04-12 Thread Mark Wielaard
Hi Bryce,

On Tue, 2006-04-11 at 15:07 -0400, Bryce McKinlay wrote:
> With GCJ and a simple benchmark, I get around a 1.5-3x performance 
> improvement depending on the String length. No mauve regressions.

According to the autobuilder (and I just checked locally against mauve)
this does trigger 2 mauve regressions:

FAIL: gnu.testlet.java.io.ObjectInputOutput.OutputTest: Serializable:
gnu.testlet.java.io.ObjectInputOutput.Test$Extern () (number 2)
FAIL: gnu.testlet.java.text.DecimalFormatSymbols.serial (number 1)

Could you have a look at those?

The autobuilder also claims that the following is a regression, but that
seems to be some bug in the compare script since this test also fails
for me before your patch:
FAIL: gnu.testlet.java.io.ObjectInputOutput.OutputTest: Serializable:
test(str=null, x=0) (number 2)

Thanks,

Mark


signature.asc
Description: This is a digitally signed message part