From d57514bd720843a20b2314fc1a9c64ceb8a928fa Mon Sep 17 00:00:00 2001 From: Juha Komulainen Date: Fri, 26 Apr 2024 12:50:20 +0300 Subject: [PATCH] Make null handling clearer in ReflectionInstantiator --- .../internal/instantiation/ReflectionInstantiator.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dalesbred/src/main/java/org/dalesbred/internal/instantiation/ReflectionInstantiator.java b/dalesbred/src/main/java/org/dalesbred/internal/instantiation/ReflectionInstantiator.java index 37f4aa9a..84987fd5 100644 --- a/dalesbred/src/main/java/org/dalesbred/internal/instantiation/ReflectionInstantiator.java +++ b/dalesbred/src/main/java/org/dalesbred/internal/instantiation/ReflectionInstantiator.java @@ -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; @@ -55,11 +56,11 @@ final class ReflectionInstantiator implements Instantiator { @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) { @@ -70,7 +71,8 @@ final class ReflectionInstantiator implements Instantiator { @SuppressWarnings("unchecked") T value = (T) v; - bindRemainingProperties(value, arguments); + if (value != null) + bindRemainingProperties(value, arguments); return value; } catch (Exception e) { throw Throwables.propagate(e);