Uploaded image for project: 'Karaf'
  1. Karaf
  2. KARAF-5362

NPE creating session with a null "in" parameter from a SessionFactory

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Trivial
    • Resolution: Fixed
    • 4.1.2
    • 4.2.12, 4.3.2
    • karaf
    • None

    Description

      The javadoc for SessionFactory#create(InputStream, PrintStream, PrintStream) says

      @param in the input stream, can be <code>null</code> if the session is only used to execute a command using {@link Session#execute(CharSequence)}
      

      When I try

      package org.apache.karaf.shell.impl.console;
      
      import static org.easymock.EasyMock.createMock;
      
      import java.io.PrintStream;
      import java.io.UnsupportedEncodingException;
      
      import org.apache.felix.service.threadio.ThreadIO;
      import org.apache.karaf.shell.api.console.SessionFactory;
      import org.junit.Test;
      
      public class SessionFactoryImplTest {
          
          @Test
          public void createWithNullInputStream() throws UnsupportedEncodingException {
              final SessionFactory sessionFactory = new SessionFactoryImpl(createMock(ThreadIO.class));
              sessionFactory.create(null, createMock(PrintStream.class), createMock(PrintStream.class));
          }
      
      }
      

      I get

      java.lang.NullPointerException: "in" is null!
      
      	at java.nio.channels.Channels.checkNotNull(Channels.java:67)
      	at java.nio.channels.Channels.newChannel(Channels.java:347)
      	at org.apache.felix.gogo.runtime.CommandSessionImpl.<init>(CommandSessionImpl.java:108)
      	at org.apache.felix.gogo.runtime.CommandProcessorImpl.createSession(CommandProcessorImpl.java:82)
      	at org.apache.felix.gogo.runtime.CommandProcessorImpl.createSession(CommandProcessorImpl.java:38)
      	at org.apache.karaf.shell.impl.console.HeadlessSessionImpl.<init>(HeadlessSessionImpl.java:67)
      	at org.apache.karaf.shell.impl.console.SessionFactoryImpl.create(SessionFactoryImpl.java:155)
      	at org.apache.karaf.shell.impl.console.SessionFactoryImpl.create(SessionFactoryImpl.java:146)
      	at org.apache.karaf.shell.impl.console.SessionFactoryImplTest.createWithNullInputStream(SessionFactoryImplTest.java:41)
      

      A work-around is to pass a non-null InputStream that should never be called if the Session is only used to execute a command using Session#execute(CharSequence).

      Attachments

        Activity

          People

            ffang Freeman Yue Fang
            emily.berk Emily Berk
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: