summaryrefslogtreecommitdiff
path: root/libjava/classpath
diff options
context:
space:
mode:
authoraph <aph@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-16 14:50:03 +0000
committeraph <aph@138bc75d-0d04-0410-961f-82ee72b054a4>2007-04-16 14:50:03 +0000
commit7d25f7ef4442f93b28aafdbdf4ce0ca73cc250d9 (patch)
treed5bceb221c5da831bdd125233d934baf43ceabe1 /libjava/classpath
parent40fe46c9811f4bc90a0f47ee442dd13140406f67 (diff)
downloadgcc-7d25f7ef4442f93b28aafdbdf4ce0ca73cc250d9.tar.gz
2007-04-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123873 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath')
-rw-r--r--libjava/classpath/ChangeLog11
-rw-r--r--libjava/classpath/javax/management/ObjectName.java106
-rw-r--r--libjava/classpath/lib/javax/management/ObjectName.classbin10052 -> 10576 bytes
3 files changed, 84 insertions, 33 deletions
diff --git a/libjava/classpath/ChangeLog b/libjava/classpath/ChangeLog
index fabbb977920..84f4c6833d6 100644
--- a/libjava/classpath/ChangeLog
+++ b/libjava/classpath/ChangeLog
@@ -1,3 +1,14 @@
+2007-04-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+ * 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.
+
2007-04-16 Andrew Haley <aph@redhat.com>
* org/omg/IOP/TaggedComponentHelper.java (read): Use
diff --git a/libjava/classpath/javax/management/ObjectName.java b/libjava/classpath/javax/management/ObjectName.java
index 0ddfb8ee6ad..a3f30efffb4 100644
--- a/libjava/classpath/javax/management/ObjectName.java
+++ b/libjava/classpath/javax/management/ObjectName.java
@@ -105,6 +105,13 @@ public class ObjectName
private static final long serialVersionUID = 1081892073854801359L;
/**
+ * The wildcard {@link ObjectName} {@code "*:*"}
+ *
+ * @since 1.6
+ */
+ public static final ObjectName WILDCARD;
+
+ /**
* The domain of the name.
*/
private transient String domain;
@@ -130,6 +137,23 @@ public class ObjectName
private transient MBeanServer server;
/**
+ * Static initializer to set up the wildcard.
+ */
+ static
+ {
+ try
+ {
+ WILDCARD = new ObjectName("");
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw (InternalError) (new InternalError("A problem occurred " +
+ "initializing the ObjectName " +
+ "wildcard.").initCause(e));
+ }
+ }
+
+ /**
* Constructs an {@link ObjectName} instance from the given string,
* which should be of the form
* &lt;domain&gt;:&lt;properties&gt;&lt;wild&gt;. &lt;domain&gt;
@@ -159,7 +183,6 @@ public class ObjectName
* Parse the name in the same form as the constructor. Used by
* readObject().
*/
-
private void parse(String name)
throws MalformedObjectNameException
{
@@ -169,32 +192,37 @@ public class ObjectName
domain = name.substring(0, domainSep);
String rest = name.substring(domainSep + 1);
properties = new TreeMap<String,String>();
- if (rest.equals("*"))
- propertyPattern = true;
- else
+ String[] pairs = rest.split(",");
+ if (pairs.length == 0 && !isPattern())
+ 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 (rest.endsWith(",*"))
+ if (pairs[a].equals("*"))
{
+ if (propertyPattern)
+ throw new MalformedObjectNameException("Multiple wildcards " +
+ "in properties.");
propertyPattern = true;
- propertyListString = rest.substring(0, rest.length() - 2);
+ continue;
}
- else
- propertyListString = rest;
- String[] pairs = propertyListString.split(",");
- if (pairs.length == 0 && !isPattern())
- throw new MalformedObjectNameException("A name that is not a " +
- "pattern must contain at " +
- "least one key-value pair.");
- for (int a = 0; a < pairs.length; ++a)
- {
- int sep = pairs[a].indexOf('=');
- String key = pairs[a].substring(0, sep);
- if (properties.containsKey(key))
- throw new MalformedObjectNameException("The same key occurs " +
- "more than once.");
- properties.put(key, pairs[a].substring(sep + 1));
- }
+ int sep = pairs[a].indexOf('=');
+ if (sep == -1)
+ throw new MalformedObjectNameException("A key must be " +
+ "followed by a value.");
+ String key = pairs[a].substring(0, sep);
+ if (properties.containsKey(key))
+ throw new MalformedObjectNameException("The same key occurs " +
+ "more than once.");
+ String value = pairs[a].substring(sep+1);
+ properties.put(key, value);
+ propertyListString += key + "=" + value + ",";
}
+ if (propertyListString.length() > 0)
+ propertyListString =
+ propertyListString.substring(0, propertyListString.length() - 1);
checkComponents();
}
@@ -263,7 +291,7 @@ public class ObjectName
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())
{
@@ -284,8 +312,9 @@ public class ObjectName
}
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)
@@ -763,10 +792,12 @@ public class ObjectName
/**
- * Serialization methods. The serialized form is the same as the
- * string parsed by the constructor.
+ * Serialize this {@link ObjectName}. The serialized
+ * form is the same as the string parsed by the constructor.
+ *
+ * @param out the output stream to write to.
+ * @throws IOException if an I/O error occurs.
*/
-
private void writeObject(ObjectOutputStream out)
throws IOException
{
@@ -777,14 +808,21 @@ public class ObjectName
buffer.append(properties);
if (isPropertyPattern())
{
- if (properties.length() == 0)
- buffer.append("*");
- else
- buffer.append(",*");
+ if (properties.length() == 0)
+ buffer.append("*");
+ else
+ buffer.append(",*");
}
out.writeObject(buffer.toString());
}
+ /**
+ * Reads the serialized form, which is that used
+ * by the constructor.
+ *
+ * @param in the input stream to read from.
+ * @throws IOException if an I/O error occurs.
+ */
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
@@ -833,10 +871,12 @@ public class ObjectName
{
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);
}
diff --git a/libjava/classpath/lib/javax/management/ObjectName.class b/libjava/classpath/lib/javax/management/ObjectName.class
index ce68245548d..5bbfcff6602 100644
--- a/libjava/classpath/lib/javax/management/ObjectName.class
+++ b/libjava/classpath/lib/javax/management/ObjectName.class
Binary files differ