On Mon, 2007-04-09 at 23:34 +0100, Andrew John Hughes wrote:
> This fixes bugs in our parsing in javax.management.ObjectName
> so that we pass all the tests recently committed to Mauve
> for parsing.
> 
> Mark, please add to the release.

Thanks. Added your backport to the release branch. All management mauve
tests except applyJDK6 now pass.

> 2007-04-09  Andrew John Hughes  <[EMAIL PROTECTED]>
> 
>       * javax/management/ObjectName.java:
>       (parse(String)): Catch multiple wildcards,
>       initialise with an empty string (so null isn't
>       appended), and emit comma even when wildcard
>       ends the list.
>       (checkComponents()): Catch newlines.
>       (quote(String)): Handle newlines and quotes
>       correctly.

Committed,

Mark
Index: javax/management/ObjectName.java
===================================================================
RCS file: /sources/classpath/classpath/javax/management/ObjectName.java,v
retrieving revision 1.11.2.2
diff -u -r1.11.2.2 ObjectName.java
--- javax/management/ObjectName.java	8 Apr 2007 17:05:29 -0000	1.11.2.2
+++ javax/management/ObjectName.java	10 Apr 2007 12:44:22 -0000
@@ -197,10 +197,14 @@
       throw new MalformedObjectNameException("A name that is not a " +
 					     "pattern must contain at " +
 					     "least one key-value pair.");
+    propertyListString = "";
     for (int a = 0; a < pairs.length; ++a)
       {
 	if (pairs[a].equals("*"))
 	  {
+	    if (propertyPattern)
+	      throw new MalformedObjectNameException("Multiple wildcards " +
+						     "in properties.");
 	    propertyPattern = true;
 	    continue;
 	  }
@@ -214,10 +218,11 @@
 						 "more than once.");
 	String value = pairs[a].substring(sep+1);
 	properties.put(key, value);
-	propertyListString += key + "=" + value;
-	if (a != (pairs.length - 1))
-	  propertyListString += ",";
+	propertyListString += key + "=" + value + ",";
       }
+    if (propertyListString.length() > 0)
+      propertyListString =
+	propertyListString.substring(0, propertyListString.length() - 1);
     checkComponents();
   }
 
@@ -286,7 +291,7 @@
     if (domain.indexOf('\n') != -1)
       throw new MalformedObjectNameException("The domain includes a newline " +
 					     "character.");
-    char[] chars = new char[] { ':', ',', '*', '?', '=' };
+    char[] chars = new char[] { '\n', ':', ',', '*', '?', '=' };
     Iterator i = properties.entrySet().iterator();
     while (i.hasNext())
       {
@@ -307,8 +312,9 @@
 	      }
 	    catch (IllegalArgumentException e)
 	      {
-		throw new MalformedObjectNameException("The quoted value is " +
-						       "invalid.");
+		throw (MalformedObjectNameException)
+		  new MalformedObjectNameException("The quoted value is " +
+						   "invalid.").initCause(e);
 	      }
 	  }
 	else if (quote != -1)
@@ -865,10 +871,12 @@
 	  {
 	    n = q.charAt(++a);
 	    if (n != '"' && n != '?' && n != '*' &&
-		n != '\n' && n != '\\')
+		n != 'n' && n != '\\')
 	      throw new IllegalArgumentException("Illegal escaped character: "
 						 + n);
 	  }
+	else if (n == '"' || n == '\n') 
+	  throw new IllegalArgumentException("Illegal character: " + n);
 	builder.append(n);
       }
 

Reply via email to