-
Notifications
You must be signed in to change notification settings - Fork 7
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
Use UncheckedIOException rather than IllegalStateException for consistency #142
Comments
I've no objections to this |
Also this:
Should throw either EDIT that whole code block looks like duplication of stuff that Configuration.builder should do or know about: InputStream resource(String resourcePath, InitialLoader.Source source) {
InputStream is = null;
if (source == InitialLoader.Source.RESOURCE) {
is = resourceStream(resourcePath);
if (is != null) {
loadedResources.add("resource:" + resourcePath);
}
} else {
File file = new File(resourcePath);
if (file.exists()) {
try {
is = new FileInputStream(file);
loadedResources.add("file:" + resourcePath);
loadedFiles.add(file);
} catch (FileNotFoundException e) {
throw new IllegalStateException(e);
}
}
}
return is;
} EDIT whoops I put this in the wrong place |
I'd say that is extremely unlikely. The design is such that Config has only the one job and I don't see that design changing. We get no real benefit from adding a Holder class per se. I don't think we need to make such a change.
Well I don't think it should be ignored, I don't see a strong argument that ignoring that FileNotFoundException is the right thing to do. It is certainly an unexpected state that a resource file exists and then doesn't when it is read. Throwing UncheckedIOException seems ok but IllegalStateException also seems ok given it has detected an unexpected and illegal state. I'll have a closer look there. |
This improves consistency with other use of UncheckedIOException
So yes lets change to use UncheckedIOException for better consistency. I'll rename this issue to reflect this change. I don't see the desire for the Holder change but it you want to continue to push for that add some more comments here and lets see. |
data
aka private holder.This improves consistency with other use of UncheckedIOException
… fallback (#146) * #142 Use UncheckedIOException rather than IllegalStateException This improves consistency with other use of UncheckedIOException * #141 DefaultResourceLoader uses ClassLoader.getSystemResourceAsStream() as fallback This should be no change when using "normal" Config/Configuration but allows users of the ConfigurationBuilder to have this fallback to ClassLoader.getSystemResourceAsStream() when the resource is not found via the usual getClass().getResourceAsStream() * #141 Use inputStream as variable name
In
io.avaje.config.Config
we haveAny static method called on
Config
will cause initialization ofdata
. Luckily and I assume this is why @rbygrave wrote it that way is that every static method inConfig
happens to accessdata
.However another developer could easily make the mistake of adding a static method that does not need
data
. Perhaps a utility method used by the builder or whatever likeconcatPath
or somethign.Thus I recommend the canonical holder pattern of a private static inner class:
All the static config methods would now do
Holder.data
fordata
.The text was updated successfully, but these errors were encountered: