Skip to content

Commit cfbdcb4

Browse files
This closes #3512
2 parents 377cda6 + 95d2de5 commit cfbdcb4

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

artemis-commons/src/main/java/org/apache/activemq/artemis/utils/collections/TypedProperties.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
import java.util.Iterator;
2424
import java.util.Map;
2525
import java.util.Map.Entry;
26+
import java.util.Objects;
2627
import java.util.Set;
2728
import java.util.function.BiConsumer;
2829
import java.util.function.Consumer;
2930
import java.util.function.Predicate;
31+
import java.util.function.Supplier;
3032

3133
import io.netty.buffer.ByteBuf;
3234
import org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException;
@@ -169,10 +171,12 @@ public Boolean getBooleanProperty(final SimpleString key) throws ActiveMQPropert
169171
throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
170172
}
171173

172-
public Byte getByteProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
174+
public Byte getByteProperty(final SimpleString key,
175+
final Supplier<Byte> defaultValue) throws ActiveMQPropertyConversionException {
176+
Objects.requireNonNull(defaultValue);
173177
Object value = doGetProperty(key);
174178
if (value == null) {
175-
return Byte.valueOf(null);
179+
return defaultValue.get();
176180
} else if (value instanceof Byte) {
177181
return (Byte) value;
178182
} else if (value instanceof SimpleString) {
@@ -181,6 +185,10 @@ public Byte getByteProperty(final SimpleString key) throws ActiveMQPropertyConve
181185
throw new ActiveMQPropertyConversionException("Invalid conversion: " + key);
182186
}
183187

188+
public Byte getByteProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
189+
return getByteProperty(key, () -> Byte.valueOf(null));
190+
}
191+
184192
public Character getCharProperty(final SimpleString key) throws ActiveMQPropertyConversionException {
185193
Object value = doGetProperty(key);
186194
if (value == null) {

artemis-commons/src/test/java/org/apache/activemq/artemis/utils/TypedPropertiesConversionTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ public void testByteProperty() throws Exception {
115115
}
116116
}
117117

118+
@Test
119+
public void testNoByteProperty() {
120+
Assert.assertEquals(0, props.size());
121+
Assert.assertNull(props.getByteProperty(key, () -> null));
122+
props.putByteProperty(key.concat('0'), RandomUtil.randomByte());
123+
Assert.assertEquals(1, props.size());
124+
Assert.assertNull(props.getByteProperty(key, () -> null));
125+
props.putNullValue(key);
126+
Assert.assertTrue(props.containsProperty(key));
127+
Assert.assertNull(props.getByteProperty(key, () -> null));
128+
}
129+
118130
@Test
119131
public void testIntProperty() throws Exception {
120132
Integer val = RandomUtil.randomInt();

artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ public SimpleString getReplyTo() {
154154

155155
@Override
156156
public RoutingType getRoutingType() {
157-
if (containsProperty(Message.HDR_ROUTING_TYPE)) {
158-
return RoutingType.getType(getByteProperty(Message.HDR_ROUTING_TYPE));
157+
final Byte maybeByte = getProperties().getByteProperty(Message.HDR_ROUTING_TYPE, () -> null);
158+
if (maybeByte == null) {
159+
return null;
159160
}
160-
return null;
161+
return RoutingType.getType(maybeByte);
161162
}
162163

163164
@Override

0 commit comments

Comments
 (0)