This is the mail archive of the java-patches@gcc.gnu.org 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]
Other format: [Raw text]

Addendum (Re: Patch: FYI: clone System properties)


Tom Tromey wrote:
> 
> Some programs (e.g., ant) expect the system properties not to have a
> parent.  While this is a bug in those programs, I've seen 3 reports of
> this problem this week alone.  It seems convenient for us to be
> compatible here, and it is easy.

Hi Tom,

    Thank you for fixing this. Your patch also fixes the problem
of getting system properties and finding out that you get an
empty enumeration on it! I don't know if this is the same 
problem as that stopping the programs you mention from working.
    
The following patch is an addendum to your patch. It implements 
clone( ) for Properties and also attempts to address Classpath 
support request number 100559 raised by crawley and pointed out 
by Mike that lists the differences in the output of 
Properties.list( ) in GCJ v/s Sun's JDK 1.3/1.4:

http://savannah.gnu.org/support/?func=detailsupport&support_id=100559&group_id=85

clone( ) is implemented as a simple shallow copy using that
in Hashtable - in particular, the "defaults" Properties object is 
shared between the clone and the original.

list( ) now looks quite similar to the output of JDK 1.3/1.4. Note 
that, as pointed out by crawley, the JDK does not truncate key 
names but does truncate values to 40 characters including ellipsis.
It also prints out values without escaping them like the 
store( ) method.

A small digression: I noticed during this work that for some reason 
TimeZone.getDefault( ) does not return the expected "IST" time-zone
on my machine and returns "GMT" instead. I must figure out why...
BTW, the MSVC runtime returns 28,800 as the value of _timezone
instead of the expected -19800 for my timezone *unless* I first
call a time function like localtime( ) or the environement variable
TZ is defined appropriately! Weirdly enough, this is also documented 
by MSDN. No, these still do not solve the default TimeZone problem.

Ranjit.


Index: ChangeLog
from  Ranjit Mathew  <rmathew@hotmail.com>

	* java/util/Properties (store): Move the code formerly in list( ),
	into this method.
	(list (PrintStream)): Just call list (PrintWriter) with a 
	PrintWriter object constructed from the given PrintStream object.
	(list (PrintWriter)): Emulate the output of Properties.list( )
	as found in JDK 1.3/1.4.
	(clone): Define.

Index: java/util/Properties.java
===================================================================
--- java/util/Properties.java	2003-02-16 16:40:42.000000000 +0530
+++ java/util/Properties.java	2003-02-16 18:44:12.000000000 +0530
@@ -378,7 +378,19 @@
     if (header != null)
       writer.println("#" + header);
-    writer.println("#" + new Date());
-    list(writer);
-    writer.flush();
+    writer.println ("#" + Calendar.getInstance ().getTime ());
+    
+    Iterator iter = entrySet ().iterator ();
+    int i = size ();
+    StringBuffer s = new StringBuffer (); // Reuse the same buffer.
+    while (--i >= 0)
+      {
+        Map.Entry entry = (Map.Entry) iter.next ();
+        formatForOutput ((String) entry.getKey (), s, true);
+        s.append ('=');
+        formatForOutput ((String) entry.getValue (), s, false);
+        writer.println (s);
+      }
+
+    writer.flush ();
   }
 
@@ -454,36 +466,25 @@
 
   /**
-   * Writes the key/value pairs to the given print stream.  They are
-   * written in the way described in the method store. This does not visit
-   * the keys in the default properties.
+   * Prints the key/value pairs to the given print stream.  This is 
+   * mainly useful for debugging purposes.
    *
-   * @param out the stream, where the key/value pairs are written to
-   * @throws ClassCastException if this property contains any key or
+   * @param out the print stream, where the key/value pairs are written to
+   * @throws ClassCastException if this property contains a key or a
    *         value that isn't a string
-   * @see #store(OutputStream, String)
+   * @see #list(PrintWriter)
    */
   public void list(PrintStream out)
   {
-    Iterator iter = entrySet().iterator();
-    int i = size();
-    StringBuffer s = new StringBuffer(); // Reuse the same buffer.
-    while (--i >= 0)
-      {
-        Map.Entry entry = (Map.Entry) iter.next();
-        formatForOutput((String) entry.getKey(), s, true);
-        s.append('=');
-        formatForOutput((String) entry.getValue(), s, false);
-        out.println(s);
-      }
+    PrintWriter writer = new PrintWriter (out);
+    list (writer);
   }
 
   /**
-   * Writes the key/value pairs to the given print writer.  They are
-   * written in the way, described in the method store.
+   * Prints the key/value pairs to the given print writer.  This is
+   * mainly useful for debugging purposes.
    *
-   * @param out the writer, where the key/value pairs are written to
-   * @throws ClassCastException if this property contains any key or
+   * @param out the print writer where the key/value pairs are written to
+   * @throws ClassCastException if this property contains a key or a
    *         value that isn't a string
-   * @see #store(OutputStream, String)
    * @see #list(PrintStream)
    * @since 1.1
@@ -491,15 +492,22 @@
   public void list(PrintWriter out)
   {
-    Iterator iter = entrySet().iterator();
-    int i = size();
-    StringBuffer s = new StringBuffer(); // Reuse the same buffer.
+    out.println ("-- listing properties --");
+
+    Iterator iter = entrySet ().iterator ();
+    int i = size ();
     while (--i >= 0)
       {
-        Map.Entry entry = (Map.Entry) iter.next();
-        formatForOutput((String) entry.getKey(), s, true);
-        s.append('=');
-        formatForOutput((String) entry.getValue(), s, false);
-        out.println(s);
+        Map.Entry entry = (Map.Entry) iter.next ();
+        out.print ((String) entry.getKey () + "=");
+
+        // JDK 1.3/1.4 restrict the printed value, but not the key,
+        // to 40 characters, including the truncating ellipsis.
+        String s = (String ) entry.getValue ();
+        if (s != null && s.length () > 40)
+          out.println (s.substring (0, 37) + "...");
+        else
+          out.println (s);
       }
+    out.flush ();
   }
 
@@ -563,3 +571,27 @@
       }
   }
+
+  /**
+   * Returns a shallow clone of this Properties object. The time 
+   * complexity and behaviour of this method is the same as that 
+   * of Hashtable.clone().
+   * 
+   * @return the clone
+   * @see Hashtable#clone()
+   */
+  public synchronized Object clone()
+  {
+    Properties copy = null;
+    try
+      {
+        copy = (Properties) super.clone ();
+      }
+    catch (CloneNotSupportedException x)
+      {
+        // Not possible.
+      }
+    copy.defaults = this.defaults;
+    return copy;
+  }
+
 } // class Properties


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