Skip to content

Commit

Permalink
Make null handling clearer in ReflectionInstantiator
Browse files Browse the repository at this point in the history
  • Loading branch information
komu committed Apr 26, 2024
1 parent eb5dced commit d57514b
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.dalesbred.internal.utils.Throwables;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
Expand Down Expand Up @@ -55,11 +56,11 @@ final class ReflectionInstantiator<T> implements Instantiator<T> {


@Override
public @NotNull T instantiate(@NotNull InstantiatorArguments arguments) {
public @Nullable T instantiate(@NotNull InstantiatorArguments arguments) {
try {
Object[] argumentArray = toArgumentArray(arguments.getValues());

Object v;
@Nullable Object v;
if (instantiator instanceof Constructor<?>) {
v = ((Constructor<?>) instantiator).newInstance(argumentArray);
} else if (instantiator instanceof Method) {
Expand All @@ -70,7 +71,8 @@ final class ReflectionInstantiator<T> implements Instantiator<T> {

@SuppressWarnings("unchecked")
T value = (T) v;
bindRemainingProperties(value, arguments);
if (value != null)
bindRemainingProperties(value, arguments);
return value;
} catch (Exception e) {
throw Throwables.propagate(e);
Expand Down

0 comments on commit d57514b

Please sign in to comment.