Skip to content

Comments

Fix possible NPE in InteractiveShellRunner#1320

Open
czpilar wants to merge 1 commit intospring-projects:mainfrom
czpilar:patches/npe-interactive-shell
Open

Fix possible NPE in InteractiveShellRunner#1320
czpilar wants to merge 1 commit intospring-projects:mainfrom
czpilar:patches/npe-interactive-shell

Conversation

@czpilar
Copy link
Contributor

@czpilar czpilar commented Feb 15, 2026

This is a small fix of potentional NPE in Interactive Shell Runner.

Consider following configuration:

package org.springframework.shell.samples.helloworld.boot;

import org.jline.reader.LineReader;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.shell.core.command.annotation.Command;
import org.springframework.shell.core.command.annotation.Option;
import org.springframework.shell.jline.JLineInputProvider;
import org.springframework.util.StringUtils;

@SpringBootApplication
public class SpringShellApplication {

	public static void main(String[] args) {
		new SpringApplicationBuilder(SpringShellApplication.class).properties("spring.shell.debug.enabled=true")
			.run(args);
	}

	@Command(name = "hello")
	public void sayHello(@Option String name) {
		System.out.println("Hello " + name + "!");
	}

	@Bean
	@Primary
	public JLineInputProvider myInputProvider(LineReader lineReader) {
		return new JLineInputProvider(lineReader) {
			@Override
			public String readInput() {
				String s = super.readInput();
				return StringUtils.hasLength(s) ? s : null;
			}
		};
	}

}

Just simple enter which produces null in readInput method will end in NPE.

obrazek

Signed-off-by: David Pilar <david@czpilar.net>
@czpilar
Copy link
Contributor Author

czpilar commented Feb 15, 2026

It is similiar issue as in #1258 where it was fixed for Non Interactive Shell Runner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant