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 {
|
||||
initializeReading();
|
||||
Object value = map.get(name);
|
||||
|
||||
if (value == null) {
|
||||
return 0;
|
||||
}
|
||||
if (value instanceof Double) {
|
||||
} else if (value instanceof Double) {
|
||||
return ((Double)value).doubleValue();
|
||||
}
|
||||
if (value instanceof Float) {
|
||||
} else if (value instanceof Float) {
|
||||
return ((Float)value).floatValue();
|
||||
}
|
||||
if (value instanceof UTF8Buffer) {
|
||||
return Float.valueOf(value.toString()).floatValue();
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return Float.valueOf(value.toString()).floatValue();
|
||||
} else if (value instanceof UTF8Buffer) {
|
||||
return Double.valueOf(value.toString()).doubleValue();
|
||||
} else if (value instanceof String) {
|
||||
return Double.valueOf(value.toString()).doubleValue();
|
||||
} 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);
|
||||
}
|
||||
|
||||
@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)
|
||||
public void testGetString() throws JMSException {
|
||||
ActiveMQMapMessage msg = new ActiveMQMapMessage();
|
||||
|
|
Loading…
Reference in New Issue