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).