My guess is that you're calling this constructor:
public Configuration(ResourceBundle resourceBundle) {
try {
new Configuration(defaultDir, defaultFileName, resourceBundle);
} catch (IOException | IndexWriteException | IndexReadException e) {
e.printStackTrace();
}
}
That doesn't do what you think it does. It tries to create a new Configuration
object, but doesn't actually do anything with it. Regardless of whether that constructor completes successfully or not, all the instance variables in this instance will have their default values.
You could chain to the other constructor instead using this
- but then you'll have to declare that this constructor can throw the same checked exceptions:
public Configuration(ResourceBundle resourceBundle)
throws IOException, IndexWriteException, IndexReadException {
this(defaultDir, defaultFileName, resourceBundle);
}
You can't catch exceptions when you chain to another constructor.
If you really (really, really) want to suppress exceptions like this, you should probably turn this into a static method, and make sure you return a reference to the newly-constructed-with-actual-data object.
public static Configuration fromResourceBundle(ResourceBundle resourceBundle) {
try {
return new Configuration(defaultDir, defaultFileName, resourceBundle);
} catch (IOException | IndexWriteException | IndexReadException e) {
// Swallowing exceptions? Really?
e.printStackTrace();
// At least the caller will get a null reference back instead of
// a broken object...
return null;
}
}