diff --git a/cdc-security/src/main/java/vn/dataplatform/security/loader/GenericServiceLoader.java b/cdc-security/src/main/java/vn/dataplatform/security/loader/GenericServiceLoader.java index fbe3379..01afb38 100644 --- a/cdc-security/src/main/java/vn/dataplatform/security/loader/GenericServiceLoader.java +++ b/cdc-security/src/main/java/vn/dataplatform/security/loader/GenericServiceLoader.java @@ -1,5 +1,6 @@ package vn.dataplatform.security.loader; +import lombok.NonNull; import vn.dataplatform.security.utils.ServiceLoaderUtils; import java.util.List; @@ -32,10 +33,7 @@ public T getInstance() { * * @return the first available implementation of the service interface */ - public T getInstance(String name) { - if (name == null) { - throw new IllegalArgumentException("name class cannot be null"); - } + public T getInstance(@NonNull String name) { List providersList = ServiceLoaderUtils.findServiceProviders(clazz); return providersList.stream().filter(provider -> name.equals(provider.getClass().getName())).findFirst().orElseThrow(RuntimeException::new); } @@ -45,10 +43,7 @@ public T getInstance(String name) { * * @return the first available implementation of the service interface */ - public T getInstance(Class clazz) { - if (clazz == null) { - throw new IllegalArgumentException("class cannot be null"); - } + public T getInstance(@NonNull Class clazz) { List providersList = ServiceLoaderUtils.findServiceProviders(clazz); return providersList.stream().filter(provider -> clazz.equals(provider.getClass())).findFirst().orElseThrow(RuntimeException::new); }