This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/main by this push:
new c4f6d45 [KARAF-5362]NPE creating session with a null in parameter
from a SessionFactory
c4f6d45 is described below
commit c4f6d451e2bbb81b1490279d73b12826d1c8e8c8
Author: Freeman Fang <[email protected]>
AuthorDate: Mon Mar 29 14:03:00 2021 -0400
[KARAF-5362]NPE creating session with a null in parameter from a
SessionFactory
---
.../shell/impl/console/HeadlessSessionImpl.java | 16 +++++++-
.../console/session/SessionFactoryImplTest.java | 44 ++++++++++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git
a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
index 4f063af..e38552c 100644
---
a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
+++
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/HeadlessSessionImpl.java
@@ -40,6 +40,7 @@ import org.apache.karaf.shell.api.console.SignalListener;
import org.apache.karaf.shell.api.console.Terminal;
import org.apache.karaf.shell.impl.console.parsing.CommandLineParser;
import org.apache.karaf.shell.support.ShellUtil;
+import org.jline.terminal.impl.DumbTerminal;
public class HeadlessSessionImpl implements Session {
@@ -66,7 +67,20 @@ public class HeadlessSessionImpl implements Session {
registry.register(this);
registry.register(registry);
// Session
- session = processor.createSession(in, out, err);
+ if (in == null || out == null || err == null) {
+ try {
+ Terminal sessionTerminal = terminal != null ? terminal :
+ new JLineTerminal(new DumbTerminal(in, out));
+ session =
processor.createSession(((org.jline.terminal.Terminal) sessionTerminal).input(),
+
((org.jline.terminal.Terminal) sessionTerminal).output(),
+
((org.jline.terminal.Terminal) sessionTerminal).output());
+ } catch (IOException e) {
+ throw new RuntimeException("Unable to create terminal", e);
+ }
+
+ } else {
+ session = processor.createSession(in, out, err);
+ }
if (parent == null) {
Properties sysProps = System.getProperties();
// iterating over sysProps.keySet() directly is not thread-safe
and may throw ConcurrentMod.Ex.,
diff --git
a/shell/core/src/test/java/org/apache/karaf/shell/impl/console/session/SessionFactoryImplTest.java
b/shell/core/src/test/java/org/apache/karaf/shell/impl/console/session/SessionFactoryImplTest.java
new file mode 100644
index 0000000..c658691
--- /dev/null
+++
b/shell/core/src/test/java/org/apache/karaf/shell/impl/console/session/SessionFactoryImplTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.karaf.shell.impl.console.session;
+
+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.apache.karaf.shell.impl.console.SessionFactoryImpl;
+
+import org.junit.Test;
+
+public class SessionFactoryImplTest {
+
+ @Test
+ public void createWithNullInputStream() throws
UnsupportedEncodingException {
+ try {
+ final SessionFactory sessionFactory = new
SessionFactoryImpl(createMock(ThreadIO.class));
+ sessionFactory.create(null, createMock(PrintStream.class),
createMock(PrintStream.class));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+}
\ No newline at end of file