[
https://issues.apache.org/activemq/browse/AMQ-1282?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_39423
]
Elliotte Rusty Harold commented on AMQ-1282:
--------------------------------------------
In fact this fails for all types except char and boolean as the following unit
tests demonstrate:
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory;
import junit.framework.TestCase;
public class MapMessageTest extends TestCase {
private ConnectionFactory factory;
private Connection connection;
private MapMessage message;
protected void setUp() throws Exception {
factory = new
ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
message = session.createMapMessage();
super.setUp();
}
protected void tearDown() throws Exception {
connection.close();
super.tearDown();
}
public void testUnmappedBooleanMessage() throws JMSException {
Object expected;
try {
expected = Boolean.valueOf(null);
}
catch (Exception ex) {
expected = ex;
}
try {
Boolean actual = message.getBoolean("foo");
assertEquals(expected, actual);
}
catch (Exception ex) {
assertEquals(expected, ex);
}
}
public void testUnmappedIntegerMessage() throws JMSException {
Object expected;
try {
expected = Integer.valueOf(null);
}
catch (Exception ex) {
expected = ex;
}
try {
Integer actual = message.getInt("foo");
assertEquals(expected, actual);
}
catch (Exception ex) {
assertEquals(expected, ex);
}
}
public void testUnmappedShortMessage() throws JMSException {
Object expected;
try {
expected = Short.valueOf(null);
}
catch (Exception ex) {
expected = ex;
}
try {
Short actual = message.getShort("foo");
assertEquals(expected, actual);
}
catch (Exception ex) {
assertEquals(expected, ex);
}
}
public void testUnmappedLongMessage() throws JMSException {
Object expected;
try {
expected = Long.valueOf(null);
}
catch (Exception ex) {
expected = ex;
}
try {
Long actual = message.getLong("foo");
assertEquals(expected, actual);
}
catch (Exception ex) {
assertEquals(expected, ex);
}
}
public void testUnmappedStringMessage() throws JMSException {
Object expected;
try {
expected = String.valueOf(null);
}
catch (Exception ex) {
expected = ex;
}
try {
String actual = message.getString("foo");
assertEquals(expected, actual);
}
catch (Exception ex) {
assertEquals(expected, ex);
}
}
public void testUnmappedCharMessage() throws JMSException {
try {
message.getChar("foo");
fail("should have thrown NullPointerException");
}
catch (NullPointerException success) {
assertNotNull(success);
}
}
public void testUnmappedByteMessage() throws JMSException {
Object expected;
try {
expected = Byte.valueOf(null);
}
catch (Exception ex) {
expected = ex;
}
try {
Byte actual = message.getByte("foo");
assertEquals(expected, actual);
}
catch (Exception ex) {
assertEquals(expected, ex);
}
}
public void testUnmappedDoubleMessage() throws JMSException {
Object expected;
try {
expected = Double.valueOf(null);
}
catch (Exception ex) {
expected = ex;
}
try {
Double actual = message.getDouble("foo");
assertEquals(expected, actual);
}
catch (Exception ex) {
assertEquals(expected, ex);
}
}
public void testUnmappedFloatMessage() throws JMSException {
Object expected;
try {
expected = Float.valueOf(null);
}
catch (Exception ex) {
expected = ex;
}
try {
Float actual = message.getFloat("foo");
assertEquals(expected, actual);
}
catch (Exception ex) {
assertEquals(expected, ex);
}
}
}
> Bad conversion of nonexistent data in MapMessage
> ------------------------------------------------
>
> Key: AMQ-1282
> URL: https://issues.apache.org/activemq/browse/AMQ-1282
> Project: ActiveMQ
> Issue Type: Bug
> Components: JMS client
> Affects Versions: 4.1.1
> Reporter: Elliotte Rusty Harold
>
> Consider simple reception code like this:
> MapMessage message = (MapMessage) consumer.receive(1000);
> int x = message.getInt("foo"));
> I notice that x is now set to zero even though there was no "foo" value in
> the map. I would have expected an exception.
> According to Gaurav Hariani <[EMAIL PROTECTED]>
> also from the spec api:
> http://java.sun.com/j2ee/1.4/docs/api/javax/jms/MapMessage.html
> Attempting to read a null value as a primitive type must be treated as
> calling the primitive's corresponding valueOf(String) conversion method with
> a null value. Since char does not support a String conversion, attempting to
> read a null value as a char must throw a NullPointerException.
> .. so you are right that it is a bug ... since Integer.valueOf(null) throws
> an Exception
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.