Skip to content

NullPointerException upon moving to 4.7.6 from 4.7.5 #2291

Closed

Description

@JessHolle

I am getting a NullPointerException apparently from within picocli code when attempting to upgrade to 4.7.6 from 4.7.5 (where the app works AOK).

I get

NullPointerException: Cannot invoke "java.lang.ClassLoader.getResource(String)" because the return value of "java.lang.Class.getClassLoader()" is null while processing argument at or before arg[2] 'foo' in [dumpSchema, -o, foo]: java.lang.NullPointerException: Cannot invoke "java.lang.ClassLoader.getResource(String)" because the return value of "java.lang.Class.getClassLoader()" is null

The related annotations are:

  @CommandLine.Command(name = "dumpSchema", separator = " ", description="...",
                       mixinStandardHelpOptions = true, versionProvider = Main.VersionProvider.class,
                       defaultValueProvider = PropertiesDefaultProvider.class)
  // used from main() via picocli annotations
  private static void dumpSchema(
    @CommandLine.Option(names = "-o", paramLabel="<outputFile>", required = false,
                        description = "...")
    @Nullable Path outputFile)

Setting -Dpicocli.trace, I get loads of INFO messages along these lines. All without any further stack traces or the like, unfortunately.

With 4.7.5 I get no such messages.

In case it matters this is for an application wrapped up as a single jar and being invoked via java -jar (and built via the com.github.johnrengelman.shadow Gradle plugin).

Activity

  1. remkop commented on May 29, 2024

    @remkop
    Owner

    Thank you for raising this.
    Class.getClassLoader() returning null is puzzling, to say the least, but the fact that you don't see this with picocli 4.7.5 suggests that it is related to a recent change.

    This may be difficult to investigate without a way to reproduce the issue. Is your application in a public repo somewhere?

  2. remkop commented on May 29, 2024

    @remkop
    Owner

    I think I found the cause:
    The change in #2107 (PropertiesDefaultProvider improvement) is missing some defensive coding.

  3. added this to the 4.7.7 milestone on May 29, 2024
  4. added a commit that references this issue on Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions