Skip to content

Commit

Permalink
[api] Log warning message if failed to load specified class (deepjava…
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu authored Jul 27, 2023
1 parent cd4f4ee commit ae84c25
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions api/src/main/java/ai/djl/repository/zoo/BaseModelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import ai.djl.util.Progress;
import ai.djl.util.Utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Type;
Expand All @@ -43,6 +46,8 @@
/** Shared code for the {@link ModelLoader} implementations. */
public class BaseModelLoader implements ModelLoader {

private static final Logger logger = LoggerFactory.getLogger(BaseModelLoader.class);

protected MRL mrl;
protected TranslatorFactory defaultFactory;

Expand Down Expand Up @@ -238,6 +243,9 @@ protected TranslatorFactory getTranslatorFactory(
if (factoryClass != null) {
ClassLoader cl = ClassLoaderUtils.getContextClassLoader();
factory = ClassLoaderUtils.initClass(cl, TranslatorFactory.class, factoryClass);
if (factory == null) {
logger.warn("Failed to load translatorFactory: {}", factoryClass);
}
}
return factory;
}
Expand Down
6 changes: 5 additions & 1 deletion api/src/main/java/ai/djl/util/ClassLoaderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public static <T> T findImplementation(Path path, Class<T> type, String classNam
(PrivilegedAction<ClassLoader>)
() -> new URLClassLoader(urls, contextCl));
if (className != null && !className.isEmpty()) {
return initClass(cl, type, className);
T impl = initClass(cl, type, className);
if (impl == null) {
logger.warn("Failed to load class: {}", className);
}
return impl;
}

T implemented = scanDirectory(cl, type, classesDir);
Expand Down

0 comments on commit ae84c25

Please sign in to comment.