Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README Example throws NullPointerException for "cmd" - ParentCommand not injected? #1415

Closed
shannonbay opened this issue Aug 19, 2021 · 4 comments
Labels
theme: integration An issue or change related to integration with other frameworks, shells or operating systems theme: shell An issue or change related to interactive (JLine) applications type: bug 🐛 type: doc 📘
Milestone

Comments

@shannonbay
Copy link

I compiled and ran the example from https://github.com/remkop/picocli/blob/master/picocli-shell-jline3/README.md
titled "JLine 3.16 and Picocli 4.4+ Example"

It gives the following error:

prompt> cmd
java.lang.NullPointerException
at picocli.shell.jline3.example.Example$MyCommand.run(Example.java:94)
at picocli.CommandLine.executeUserObject(CommandLine.java:1939)
at picocli.CommandLine.access$1300(CommandLine.java:145)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
at picocli.CommandLine.execute(CommandLine.java:2078)
at picocli.shell.jline3.PicocliCommands.invoke(PicocliCommands.java:283)
at org.jline.console.impl.SystemRegistryImpl.execute(SystemRegistryImpl.java:1128)
at org.jline.console.impl.SystemRegistryImpl.execute(SystemRegistryImpl.java:1173)
at picocli.shell.jline3.example.Example.main(Example.java:176)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:254)
at java.lang.Thread.run(Thread.java:748)

Here is my dependency tree:
sbay@VDXSPK85051532:/fov/lrf/shell 16:19 (master *+)$ mvn dependency:tree
[INFO] After Session Start
[INFO] Setting git.branch to 'SNAPSHOT'
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< nz.co.spark.ims.lrf:shell >----------------------
[INFO] Building Spark LRF Shell 0.1.16-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ shell ---
[INFO] nz.co.spark.ims.lrf:shell:jar:0.1.16-SNAPSHOT
[INFO] +- org.fusesource.jansi:jansi:jar:2.1.0:compile
[INFO] - info.picocli:picocli-shell-jline3:jar:4.6.1:compile
[INFO] +- info.picocli:picocli:jar:4.6.1:compile
[INFO] +- org.jline:jline:jar:3.17.1:compile
[INFO] - org.jline:jline-console:jar:3.17.1:compile
[INFO] +- org.jline:jline-builtins:jar:3.17.1:compile
[INFO] | - org.jline:jline-reader:jar:3.17.1:compile
[INFO] - org.jline:jline-style:jar:3.17.1:compile
[INFO] - org.jline:jline-terminal:jar:3.17.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.161 s
[INFO] Finished at: 2021-08-19T16:22:21+12:00
[INFO] ------------------------------------------------------------------------
sbay@VDXSPK85051532:/fov/lrf/shell 16:22 (master *+)$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

@shannonbay shannonbay changed the title Example throws NullPointerException for "cmd" - ParentCommand not injected? README Example throws NullPointerException for "cmd" - ParentCommand not injected? Aug 19, 2021
@shannonbay
Copy link
Author

It appears the PrintWriter is not initialised in CliCommands

@remkop remkop closed this as completed in e6d072b Aug 19, 2021
@remkop
Copy link
Owner

remkop commented Aug 19, 2021

Thanks for raising this!
I think I fixed it now. Can you check?

@remkop remkop added type: bug 🐛 type: doc 📘 theme: integration An issue or change related to integration with other frameworks, shells or operating systems theme: shell An issue or change related to interactive (JLine) applications labels Aug 19, 2021
@remkop remkop added this to the 4.6.2 milestone Aug 19, 2021
@shannonbay
Copy link
Author

Awesome, works perfectly. I had managed to get it going with @SPEC

@remkop
Copy link
Owner

remkop commented Aug 19, 2021

Great 👍
Thanks for checking!
And thanks again for raising this!

MarkoMackic pushed a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
MarkoMackic added a commit to MarkoMackic/picocli that referenced this issue Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: integration An issue or change related to integration with other frameworks, shells or operating systems theme: shell An issue or change related to interactive (JLine) applications type: bug 🐛 type: doc 📘
Projects
None yet
Development

No branches or pull requests

2 participants