[AMQ-7291] rework fix to initializeWriting but just with the read only properties check

This commit is contained in:
gtully 2020-05-21 10:41:58 +01:00
parent 173426c55c
commit 62cfe83e9d
3 changed files with 31 additions and 2 deletions

View File

@ -832,6 +832,10 @@ public class ActiveMQBytesMessage extends ActiveMQMessage implements BytesMessag
private void initializeWriting() throws JMSException { private void initializeWriting() throws JMSException {
checkReadOnlyBody(); checkReadOnlyBody();
initializeWritingNoCheck();
}
private void initializeWritingNoCheck() throws JMSException {
if (this.dataOut == null) { if (this.dataOut == null) {
this.bytesOut = new ByteArrayOutputStream(); this.bytesOut = new ByteArrayOutputStream();
OutputStream os = bytesOut; OutputStream os = bytesOut;
@ -914,7 +918,8 @@ public class ActiveMQBytesMessage extends ActiveMQMessage implements BytesMessag
@Override @Override
public void setObjectProperty(String name, Object value) throws JMSException { public void setObjectProperty(String name, Object value) throws JMSException {
initializeWriting(); checkReadOnlyProperties();
initializeWritingNoCheck();
super.setObjectProperty(name, value); super.setObjectProperty(name, value);
} }

View File

@ -736,7 +736,7 @@ public class ActiveMQMessage extends Message implements org.apache.activemq.Mess
setObjectProperty(name, value); setObjectProperty(name, value);
} }
private void checkReadOnlyProperties() throws MessageNotWriteableException { protected void checkReadOnlyProperties() throws MessageNotWriteableException {
if (readOnlyProperties) { if (readOnlyProperties) {
throw new MessageNotWriteableException("Message properties are read-only"); throw new MessageNotWriteableException("Message properties are read-only");
} }

View File

@ -269,6 +269,30 @@ public class ActiveMQBytesMessageTest extends TestCase {
} }
} }
public void testClearProperties() throws Exception {
ActiveMQBytesMessage bytesMessage = new ActiveMQBytesMessage();
bytesMessage.setIntProperty("one", 1);
// simulate send
bytesMessage.onSend();
assertEquals(1, bytesMessage.getIntProperty("one"));
assertTrue(bytesMessage.isReadOnlyProperties());
try {
bytesMessage.setIntProperty("two", 2);
fail("should have thrown b/c readonly");
} catch (MessageNotWriteableException expected) {
}
// allow writing new properties
bytesMessage.clearProperties();
assertFalse(bytesMessage.propertyExists("one"));
assertFalse(bytesMessage.isReadOnlyProperties());
bytesMessage.setIntProperty("two", 2);
assertEquals(2, bytesMessage.getIntProperty("two"));
}
public void testReset() throws JMSException { public void testReset() throws JMSException {
ActiveMQBytesMessage message = new ActiveMQBytesMessage(); ActiveMQBytesMessage message = new ActiveMQBytesMessage();
try { try {