avaje-config icon indicating copy to clipboard operation
avaje-config copied to clipboard

Inconsistency with builder and initial loader. Default resource loader does not use the System class loader?

Open agentgt opened this issue 1 month ago • 19 comments

InitialLoader / InitialLoaderContext does several things different than what the Configuration.builder does that are very hard to replicate with the builder.

For example let us say I want to replicate most of the default initialization: One them is this:

Configuration.builder()
.load("application.properties")
.load("application-test.properties")
.build();

There are several problems with the above. I can't specify a maybeLoad and or fallbacks. I also had the surprise that the default resourceLoader does not do:

ClassLoader.getSystemResourceAsStream which is done in io.avaje.config.InitialLoadContext:

  private InputStream resourceStream(String resourcePath) {
    InputStream is = resourceLoader.getResourceAsStream(resourcePath);
    if (is == null) {
      // search the module path for top level resource
      is = ClassLoader.getSystemResourceAsStream(resourcePath);
    }
    return is;
  }

It seems there is a lot of duplication between the builder and InitialLoadContext.

The above I would expect:

  private InputStream resourceStream(String resourcePath) {
    return resourceLoader.getResourceAsStream(resourcePath);
  }

And the default resourceLoader to handle the ClassLoader.getSystemResourceAsStream(resourcePath) fallback.

agentgt avatar May 03 '24 17:05 agentgt