-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
11 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* | ||
* Copyright 2024 Ekalia <[email protected]> | ||
* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
|
@@ -34,6 +34,7 @@ | |
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
/** | ||
|
@@ -65,7 +66,7 @@ public Injector() { | |
* @param instance The instance to register. | ||
*/ | ||
public void registerInjection(@NotNull Object instance) { | ||
this.registerInjection(injection, InjectPriority.NORMAL); | ||
this.registerInjection(instance, InjectPriority.NORMAL); | ||
} | ||
|
||
/** | ||
|
@@ -196,7 +197,8 @@ private void loadProvidesClass(Class<?> aClass, Map<Class<?>, InjectPriority> pr | |
} | ||
} catch (NoClassDefFoundError e) { | ||
Injector.LOGGER.error(Injector.CANNOT_LOAD_PROVIDED_CLASS, aClass.getName(), e.getMessage()); | ||
} catch (Throwable t) { //NOSONAR We want to catch all exceptions and throwables as ClassGraph throws Throwables and not Exceptions | ||
} catch ( | ||
Throwable t) { //NOSONAR We want to catch all exceptions and throwables as ClassGraph throws Throwables and not Exceptions | ||
Injector.LOGGER.error(Injector.CANNOT_LOAD_PROVIDED_CLASS, t, aClass.getName(), t.getMessage()); | ||
} | ||
} | ||
|
@@ -243,12 +245,12 @@ public void injectAtRuntime(Object instance, String packageName, ClassLoader cla | |
@SuppressWarnings("java:S3011") // "Make sure that this accessibility update is safe here." | ||
private void injectIntoField(Field field) throws IllegalAccessException { | ||
if (!field.isAnnotationPresent(Inject.class)) { | ||
continue; | ||
return; | ||
} | ||
|
||
// Try to access field via reflection | ||
if (!field.trySetAccessible()) { | ||
continue; | ||
return; | ||
} | ||
|
||
Object optimalValue = null; | ||
|
@@ -303,8 +305,8 @@ public ClassGraph getClassGraph() { | |
* Get the injected object for the given class | ||
* | ||
* @param clazz The class type | ||
* @param <T> The object type | ||
* @return An {@link Optional} that contains the injected object for the given class, if present | ||
* @param <T> The object type | ||
*/ | ||
public <T> Optional<T> get(Class<T> clazz) { | ||
return Optional.ofNullable(this.classes.get(clazz)).map(Tuple2::getT2).map(clazz::cast); | ||
|