This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 9e2d19bd90 Treat TabularDataSupport similarly to an array of
CompositeData
9e2d19bd90 is described below
commit 9e2d19bd90e3b7d849550cf330e764122af15187
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Jun 12 17:58:19 2026 +0100
Treat TabularDataSupport similarly to an array of CompositeData
This ignores the calculated key but I think that is OK
Authored by CoPilot / GPT-5.4
---
.../apache/catalina/ant/jmx/JMXAccessorTask.java | 24 +++-----
.../catalina/ant/jmx/TestJMXAccessorTask.java | 71 ++++++++++++++++++++++
2 files changed, 78 insertions(+), 17 deletions(-)
diff --git a/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java
b/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java
index 8629b91c0c..f3260ee3ee 100644
--- a/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java
+++ b/java/org/apache/catalina/ant/jmx/JMXAccessorTask.java
@@ -22,7 +22,6 @@ import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -32,7 +31,6 @@ import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
@@ -672,8 +670,8 @@ public class JMXAccessorTask extends
BaseRedirectorHelperTask {
if (propertyPrefix == null) {
propertyPrefix = "";
}
- if (result instanceof CompositeDataSupport) {
- CompositeDataSupport data = (CompositeDataSupport) result;
+ if (result instanceof CompositeData) {
+ CompositeData data = (CompositeData) result;
CompositeType compositeType = data.getCompositeType();
Set<String> keys = compositeType.keySet();
for (String key : keys) {
@@ -685,19 +683,11 @@ public class JMXAccessorTask extends
BaseRedirectorHelperTask {
createProperty(propertyPrefix + "." + key, value);
}
}
- } else if (result instanceof TabularDataSupport) {
- TabularDataSupport data = (TabularDataSupport) result;
- for (Object key : data.keySet()) {
- for (Object key1 : ((List<?>) key)) {
- CompositeData valuedata = data.get(new Object[] { key1 });
- Object value = valuedata.get("value");
- OpenType<?> type =
valuedata.getCompositeType().getType("value");
- if (type instanceof SimpleType<?>) {
- setProperty(propertyPrefix + "." + key1, value);
- } else {
- createProperty(propertyPrefix + "." + key1, value);
- }
- }
+ } else if (result instanceof TabularDataSupport data) {
+ int rowIndex = 0;
+ for (Object value : data.values()) {
+ createProperty(propertyPrefix + "." + rowIndex, value);
+ rowIndex++;
}
} else if (result.getClass().isArray()) {
if (isSeparatearrayresults()) {
diff --git a/test/org/apache/catalina/ant/jmx/TestJMXAccessorTask.java
b/test/org/apache/catalina/ant/jmx/TestJMXAccessorTask.java
new file mode 100644
index 0000000000..3531a52ac6
--- /dev/null
+++ b/test/org/apache/catalina/ant/jmx/TestJMXAccessorTask.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.ant.jmx;
+
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.openmbean.TabularType;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestJMXAccessorTask {
+
+ @Test
+ public void testCreatePropertyForTabularDataSupport() throws Exception {
+ JMXAccessorTask task = new JMXAccessorTask();
+
+ task.createProperty("tabular", createTabularData());
+
+ Assert.assertEquals("0", task.getProperty("tabular.0.id"));
+ Assert.assertEquals("alpha",
task.getProperty("tabular.0.details.name"));
+ Assert.assertEquals("7", task.getProperty("tabular.0.count"));
+ Assert.assertEquals("1", task.getProperty("tabular.1.id"));
+ Assert.assertEquals("beta",
task.getProperty("tabular.1.details.name"));
+ Assert.assertEquals("11", task.getProperty("tabular.1.count"));
+ }
+
+
+ private static TabularDataSupport createTabularData() throws
OpenDataException {
+ CompositeType detailsType = new CompositeType("details", "details",
new String[] { "name" },
+ new String[] { "name" }, new OpenType<?>[] { SimpleType.STRING
});
+ CompositeType rowType = new CompositeType("row", "row", new String[] {
"id", "details", "count" },
+ new String[] { "id", "details", "count" },
+ new OpenType<?>[] { SimpleType.STRING, detailsType,
SimpleType.INTEGER });
+ TabularDataSupport tabularData = new TabularDataSupport(new
TabularType("table", "table", rowType,
+ new String[] { "id" }));
+
+ tabularData.put(createRow(rowType, detailsType, "0", "alpha",
Integer.valueOf(7)));
+ tabularData.put(createRow(rowType, detailsType, "1", "beta",
Integer.valueOf(11)));
+
+ return tabularData;
+ }
+
+
+ private static CompositeDataSupport createRow(CompositeType rowType,
CompositeType detailsType, String id,
+ String detailName, Integer count) throws OpenDataException {
+ CompositeDataSupport details = new CompositeDataSupport(detailsType,
new String[] { "name" },
+ new Object[] { detailName });
+
+ return new CompositeDataSupport(rowType, new String[] { "id",
"details", "count" },
+ new Object[] { id, details, count });
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]