marschall / jakarta-jms-adapter

adapts a javax.jms JMS provider to a jakarta.jms JMS provider
6 stars 3 forks source link

Wrapper throws an exception if object is null #2

Closed victorgawk closed 7 months ago

victorgawk commented 7 months ago

Wrapper should return null if object is null.

marschall commented 7 months ago

Out of curiosity, what was null?

victorgawk commented 7 months ago

The null was a jakarta.jms.Destination instance when creating a message producer in a JMS session. I pass null because the producer in my application does not have a specified destination.

Code example:

import java.util.Hashtable;
import javax.naming.InitialContext;
import com.github.marschall.jakartajmsadapter.JakartaConnectionFactory;
import com.github.marschall.jakartajmsadapter.JakartaQueue;
import jakarta.jms.Connection;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.MessageProducer;
import jakarta.jms.Queue;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;

// ...

Hashtable<String, String> env = new Hashtable<>();
env.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
env.put("java.naming.provider.url", "t3://host:port");
InitialContext ctx = new InitialContext(env);

ConnectionFactory connectionFactory = new JakartaConnectionFactory((javax.jms.ConnectionFactory)
    ctx.lookup("connection factory JNDI"));

Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

MessageProducer messageProducer = session.createProducer(null); // <--- The error was happening here

// I choose the destination of the message only when I call the `send` method
Queue queue = new JakartaQueue((javax.jms.Queue) ctx.lookup("queue JNDI here"));
TextMessage message = session.createTextMessage("message here");

messageProducer.send(queue, message);