You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2016/09/04 18:38:19 UTC
[03/36] logging-log4j2 git commit: Migrate Loader.isClassAvailable()
to LoaderUtil
Migrate Loader.isClassAvailable() to LoaderUtil
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6d4c4551
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6d4c4551
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6d4c4551
Branch: refs/heads/master
Commit: 6d4c45519a1d80476167cfe5693082ccd7f4c04d
Parents: e796f08
Author: Matt Sicker <bo...@gmail.com>
Authored: Wed Jun 15 14:07:29 2016 -0500
Committer: Matt Sicker <bo...@gmail.com>
Committed: Wed Jun 15 14:07:29 2016 -0500
----------------------------------------------------------------------
.../apache/logging/log4j/util/LoaderUtil.java | 19 +++++++++++++++++++
.../apache/logging/log4j/core/util/Loader.java | 10 +---------
2 files changed, 20 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6d4c4551/log4j-api/src/main/java/org/apache/logging/log4j/util/LoaderUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/LoaderUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/LoaderUtil.java
index b5f626d..6c66486 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/LoaderUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/LoaderUtil.java
@@ -104,6 +104,25 @@ public final class LoaderUtil {
}
/**
+ * Determines if a named Class can be loaded or not.
+ *
+ * @param className The class name.
+ * @return {@code true} if the class could be found or {@code false} otherwise.
+ * @since 2.7
+ */
+ public static boolean isClassAvailable(final String className) {
+ try {
+ final Class<?> clazz = loadClass(className);
+ return clazz != null;
+ } catch (final ClassNotFoundException e) {
+ return false;
+ } catch (final Throwable e) {
+ LowLevelLogUtil.logException("Unknown error checking for existence of class: " + className, e);
+ return false;
+ }
+ }
+
+ /**
* Loads a class by name. This method respects the {@link #IGNORE_TCCL_PROPERTY} Log4j property. If this property is
* specified and set to anything besides {@code false}, then the default ClassLoader will be used.
*
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6d4c4551/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
index bb35752..e3c5140 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Loader.java
@@ -308,14 +308,6 @@ public final class Loader {
* @return {@code true} if the class could be found or {@code false} otherwise.
*/
public static boolean isClassAvailable(final String className) {
- try {
- final Class<?> clazz = loadClass(className);
- return clazz != null;
- } catch (final ClassNotFoundException e) {
- return false;
- } catch (final Throwable e) {
- LOGGER.trace("Unknown error checking for existence of class [{}].", className, e);
- return false;
- }
+ return LoaderUtil.isClassAvailable(className);
}
}