Skip to content

Commit

Permalink
[Minor] Better exception handling in I18nMessage.findAllBundles()
Browse files Browse the repository at this point in the history
  • Loading branch information
eitch committed Jul 12, 2024
1 parent 3a16e3a commit 128d95c
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions utils/src/main/java/li/strolch/utils/I18nMessage.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package li.strolch.utils;

import static java.util.Collections.emptySet;
import static li.strolch.utils.collections.SynchronizedCollections.synchronizedMapOfSets;
import static li.strolch.utils.helper.ExceptionHelper.formatException;
import static li.strolch.utils.helper.ExceptionHelper.getExceptionMessageWithCauses;
import static li.strolch.utils.helper.StringHelper.EMPTY;
import static li.strolch.utils.helper.StringHelper.isEmpty;
import li.strolch.utils.collections.MapOfMaps;
import li.strolch.utils.collections.MapOfSets;
import li.strolch.utils.collections.TypedTuple;
import li.strolch.utils.dbc.DBC;
import li.strolch.utils.helper.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -17,13 +18,12 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import li.strolch.utils.collections.MapOfMaps;
import li.strolch.utils.collections.MapOfSets;
import li.strolch.utils.collections.TypedTuple;
import li.strolch.utils.dbc.DBC;
import li.strolch.utils.helper.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.Collections.emptySet;
import static li.strolch.utils.collections.SynchronizedCollections.synchronizedMapOfSets;
import static li.strolch.utils.helper.ExceptionHelper.formatException;
import static li.strolch.utils.helper.ExceptionHelper.getExceptionMessageWithCauses;
import static li.strolch.utils.helper.StringHelper.EMPTY;
import static li.strolch.utils.helper.StringHelper.isEmpty;

public class I18nMessage {

Expand Down Expand Up @@ -304,15 +304,23 @@ private static void findAllBundles() {
String baseName = tuple.getFirst();
Locale locale = tuple.getSecond();

ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,
new CustomControl(jarFile.getInputStream(je)));
String propertyName = entryName.replace('/', '.');
ResourceBundle bundle;
try {
bundle = ResourceBundle.getBundle(baseName, locale,
new CustomControl(jarFile.getInputStream(je)));
} catch (Exception e) {
logger.error("Failed to load bundle {} {} from {} from JAR {}", baseName, locale,
propertyName, file.getName(), e);
continue;
}

bundleMap.addElement(bundle.getBaseBundleName(), bundle.getLocale(), bundle);

String propertyName = entryName.replace('/', '.');
logger.info(" Loaded bundle {} {} from {} from JAR {}", bundle.getBaseBundleName(),
bundle.getLocale(), propertyName, file.getName());
}
} catch (Exception e) {
logger.error("Failed to read JAR {}", file.getName(), e);
}
}

Expand All @@ -335,6 +343,10 @@ private static void findAllBundles() {
ResourceBundle bundle;
try (FileInputStream in = new FileInputStream(propertyFile)) {
bundle = ResourceBundle.getBundle(baseName, locale, new CustomControl(in));
} catch (Exception e) {
logger.error("Failed to load bundle {} {} from file {}", baseName, locale,
propertyFile.getName(), e);
continue;
}

bundleMap.addElement(bundle.getBaseBundleName(), bundle.getLocale(), bundle);
Expand Down

0 comments on commit 128d95c

Please sign in to comment.