jbonofre commented on code in PR #1853:
URL: https://github.com/apache/activemq/pull/1853#discussion_r3005722654


##########
activemq-client/src/main/java/org/apache/activemq/command/ActiveMQMessage.java:
##########
@@ -501,6 +501,19 @@ public void setObjectProperty(String name, Object value, 
boolean checkReadOnly)
 
         checkValidObject(value);
         value = convertScheduled(name, value);
+
+        // Strict Compliance Check For Provider-Set JMSX Properties
+        ActiveMQConnection conn = getConnection();
+        if (conn != null && conn.isStrictCompliance()) {
+            if ("JMSXDeliveryCount".equals(name) ||
+                    "JMSXRcvTimestamp".equals(name) ||
+                    "JMSXState".equals(name) ||
+                    "JMSXProducerTXID".equals(name) ||
+                    "JMSXConsumerTXID".equals(name)) {
+                throw new MessageNotWriteableException("Provider-set JMSX 
property '" + name + "' cannot be set by a client under strict compliance.");

Review Comment:
   I'm not sure we should use `MessageNotWriteableException` here.
   
   `MessageNotWriiteableException` is specified in JMS for when a message is in 
read-only mode (received). For a provider-only property that clients should 
never set, I think a `JMSException` with a clear message might be more 
semantically accurate. 
   
   The distinction matters because a client catching 
`MessageNotWriteableException` might assume calling `clearProperties()` would 
fix it, but it won't (since this is a permanent restriction, not a state-based 
one).



##########
activemq-unit-tests/src/test/java/org/apache/activemq/StrictComplianceProviderJMSXPropertyTest.java:
##########
@@ -0,0 +1,138 @@
+/**
+ * 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.activemq;
+
+import jakarta.jms.Connection;
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.Session;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+public class StrictComplianceProviderJMSXPropertyTest {
+
+    private BrokerService broker;
+    private String connectionUri;
+
+    @Before
+    public void setUp() throws Exception {
+        broker = new BrokerService();
+        broker.setPersistent(false);
+        broker.setUseJmx(false);
+        broker.addConnector("vm://localhost");
+        broker.start();
+        broker.waitUntilStarted();
+        connectionUri = 
broker.getTransportConnectors().get(0).getPublishableConnectString();
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        if (broker != null) {
+            broker.stop();
+            broker.waitUntilStopped();
+        }
+    }
+
+    @Test
+    public void testLegacyModeAllowsProviderSetJMSXProperties() throws 
Exception {
+        ActiveMQConnectionFactory factory = new 
ActiveMQConnectionFactory(connectionUri);
+
+        // Legacy mode (default)
+        factory.setStrictCompliance(false);
+
+        try (Connection connection = factory.createConnection();
+             Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE)) {
+
+            connection.start();
+            Message message = (Message) session.createMessage();

Review Comment:
   I don't see `Message` in the import, I think it won't compile 😄 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to