You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When following the instructions at http://picocli.info/autocomplete.html to generate a bash completion script for a non-public @Command class, picocli.AutoComplete throws the following exception:
java.lang.IllegalAccessException: Class picocli.AutoComplete$App can not access a member of class bisq.cli.Bisq with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:102)
at java.lang.Class.newInstance(Class.java:436)
at picocli.AutoComplete$App.run(AutoComplete.java:89)
at picocli.CommandLine.execute(CommandLine.java:775)
at picocli.CommandLine.access$700(CommandLine.java:139)
at picocli.CommandLine$RunLast.handle(CommandLine.java:998)
at picocli.CommandLine$RunLast.handle(CommandLine.java:966)
at picocli.CommandLine$AbstractParseResultHandler.handleParseResult(CommandLine.java:831)
at picocli.CommandLine.parseWithHandlers(CommandLine.java:1182)
at picocli.CommandLine.run(CommandLine.java:1544)
at picocli.CommandLine.run(CommandLine.java:1494)
at picocli.AutoComplete.main(AutoComplete.java:51)
This is because (a) bisq.cli.Bisq is declared (intentionally) with package-private visibility, and (b) because picocli.AutoComplete$App.run attempts to reflectively instantiate it using Class.newInstance(), which respects declared visibility modifiers and provides no option to override them.
Solution
Instead of Class.newInstance(), first get the class's no-arg Constructor with Class.getConstructor(), then call setAccessible(true) on it followed by newInstance. This will allow users to keep declaring their @Command classes with whatever visibility they see fit.
The text was updated successfully, but these errors were encountered:
Understood. I will look into this. Can you please provide a failing JUnit test so I can reproduce the issue and be confident that my changes fix the issue.
If you want to go ahead and provide a pull request with a fix that’d be even better!
Problem
When following the instructions at http://picocli.info/autocomplete.html to generate a bash completion script for a non-public
@Command
class,picocli.AutoComplete
throws the following exception:This is because (a)
bisq.cli.Bisq
is declared (intentionally) with package-private visibility, and (b) becausepicocli.AutoComplete$App.run
attempts to reflectively instantiate it usingClass.newInstance()
, which respects declared visibility modifiers and provides no option to override them.Solution
Instead of
Class.newInstance()
, first get the class's no-argConstructor
withClass.getConstructor()
, then callsetAccessible(true)
on it followed bynewInstance
. This will allow users to keep declaring their@Command
classes with whatever visibility they see fit.The text was updated successfully, but these errors were encountered: