mirror of https://github.com/apache/activemq.git
Fix getDouble to use Double.valueOf instead of Float.valueOf for conversions.
This commit is contained in:
parent
6e038d5ffd
commit
4b346360be
|
@ -437,22 +437,19 @@ public class ActiveMQMapMessage extends ActiveMQMessage implements MapMessage {
|
||||||
public double getDouble(String name) throws JMSException {
|
public double getDouble(String name) throws JMSException {
|
||||||
initializeReading();
|
initializeReading();
|
||||||
Object value = map.get(name);
|
Object value = map.get(name);
|
||||||
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
} else if (value instanceof Double) {
|
||||||
if (value instanceof Double) {
|
|
||||||
return ((Double)value).doubleValue();
|
return ((Double)value).doubleValue();
|
||||||
}
|
} else if (value instanceof Float) {
|
||||||
if (value instanceof Float) {
|
|
||||||
return ((Float)value).floatValue();
|
return ((Float)value).floatValue();
|
||||||
}
|
} else if (value instanceof UTF8Buffer) {
|
||||||
if (value instanceof UTF8Buffer) {
|
return Double.valueOf(value.toString()).doubleValue();
|
||||||
return Float.valueOf(value.toString()).floatValue();
|
} else if (value instanceof String) {
|
||||||
}
|
return Double.valueOf(value.toString()).doubleValue();
|
||||||
if (value instanceof String) {
|
|
||||||
return Float.valueOf(value.toString()).floatValue();
|
|
||||||
} else {
|
} else {
|
||||||
throw new MessageFormatException(" cannot read a double from " + value.getClass().getName());
|
throw new MessageFormatException("Cannot read a double from " + value.getClass().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,22 @@ public class ActiveMQMapMessageTest {
|
||||||
assertTrue(msg.getDouble(this.name) == 1.5);
|
assertTrue(msg.getDouble(this.name) == 1.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
|
public void testGetDoubleWithMaxValue() throws JMSException {
|
||||||
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
|
msg.setDouble(this.name, Double.MAX_VALUE);
|
||||||
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
|
assertEquals(Double.MAX_VALUE, msg.getDouble(this.name), 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 10000)
|
||||||
|
public void testGetDoubleWithMaxValueAsString() throws JMSException {
|
||||||
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
|
msg.setString(this.name, String.valueOf(Double.MAX_VALUE));
|
||||||
|
msg = (ActiveMQMapMessage) msg.copy();
|
||||||
|
assertEquals(Double.MAX_VALUE, msg.getDouble(this.name), 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(timeout = 10000)
|
@Test(timeout = 10000)
|
||||||
public void testGetString() throws JMSException {
|
public void testGetString() throws JMSException {
|
||||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||||
|
|
Loading…
Reference in New Issue