Results 1 to 3 of 3

Thread: dead code in JmsTransactionManager

  1. #1
    Join Date
    Jul 2011
    Posts
    6

    Question dead code in JmsTransactionManager

    I stumbeled upon the following code in JmsTransactionManager
    Code:
    	protected void doBegin(Object transaction, TransactionDefinition definition) {
    		//...
    		Connection con = null;
    		Session session = null;
    		try {
    			con = createConnection();
    			session = createSession(con);
    			//..
    		}
    		catch (JMSException ex) {
    			if (session != null) { //session will always be null
    				try {
    					session.close();
    				}
    				catch (Throwable ex2) {
    					// ignore
    				}
    			}
    			if (con != null) {
    				//..
    			}
    			throw new CannotCreateTransactionException("Could not create JMS transaction", ex);
    		}
    	}
    The point is that inside the catch-block session will always be null. There are only two lines that can throw JMSException and these are the assignments for con and session. session is only assigned one inside the try block and this is the last line that can throw JMSException. Therefore session will always be null inside the catch-block.

  2. #2
    Join Date
    Apr 2007
    Posts
    307

    Default

    Chris Beams
    Spring Framework committer, VMware
    http://github.com/cbeams

  3. #3
    Join Date
    Jul 2011
    Posts
    6

    Default

    Well to be honest I was Eclipse that found it. Unfortunatley Spring has quite a lot of Eclipse warnings that make it hard to see the important ones. That's why I submitted https://github.com/SpringSource/spri...mework/pull/34

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •