Skip to content

Commit

Permalink
[update] security code
Browse files Browse the repository at this point in the history
  • Loading branch information
tuancamtbtx committed Dec 13, 2023
1 parent 171699e commit 014a696
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package vn.dataplatform.security.loader;

import lombok.NonNull;
import vn.dataplatform.security.utils.ServiceLoaderUtils;

import java.util.List;
Expand Down Expand Up @@ -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<T> providersList = ServiceLoaderUtils.findServiceProviders(clazz);
return providersList.stream().filter(provider -> name.equals(provider.getClass().getName())).findFirst().orElseThrow(RuntimeException::new);
}
Expand All @@ -45,10 +43,7 @@ public T getInstance(String name) {
*
* @return the first available implementation of the service interface
*/
public T getInstance(Class<T> clazz) {
if (clazz == null) {
throw new IllegalArgumentException("class cannot be null");
}
public T getInstance(@NonNull Class<T> clazz) {
List<T> providersList = ServiceLoaderUtils.findServiceProviders(clazz);
return providersList.stream().filter(provider -> clazz.equals(provider.getClass())).findFirst().orElseThrow(RuntimeException::new);
}
Expand Down

0 comments on commit 014a696

Please sign in to comment.