Github user garydgregory commented on a diff in the pull request:
https://github.com/apache/logging-log4j2/pull/93#discussion_r127725532
--- Diff:
log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java
---
@@ -329,6 +331,49 @@ private void loadImplementationsInJar(final Test test,
final String parent, fina
}
/**
+ * Finds matching classes within a jar files that contains a folder
structure matching the package structure. If the
+ * File is not a JarFile or does not exist a warning will be logged,
but no error will be raised.
+ *
+ * @param test
+ * a Test used to filter the classes that are discovered
+ * @param parent
+ * the parent package under which classes must be in order to
be considered
+ * @param connection
+ * the URL Connection to be examined for classes
+ */
+ private void loadImplementationsInJar(final ResolverUtil.Test test,
final String parent, final URLConnection connection) {
+
+ JarFile jarFile = null;
+ try {
+ if (connection != null && connection instanceof
JarURLConnection) {
+ JarURLConnection jarURLConnection = (JarURLConnection)
connection;
+ jarFile = jarURLConnection.getJarFile();
+ final Enumeration<JarEntry> entries = jarFile.entries();
+
+ while (entries.hasMoreElements()) {
+ JarEntry entry = entries.nextElement();
+ String name = entry.getName();
+
+ if (!entry.isDirectory() && name.startsWith(parent) &&
this.isTestApplicable(test, name)) {
+ this.addIfMatching(test, name);
+ }
+ }
+ }
+ }catch (IOException e){
+ LOGGER.error("Could not search JAR file '{}' for classes
matching criteria {}, file not found", jarFile,
+ test, e);
+ }finally {
+ if (jarFile != null){
+ try {
--- End diff --
Is it possible to simplify with a try-with-resources block?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---