From 4f16b35e434a2d5dd86f65be4ebef2c074c51189 Mon Sep 17 00:00:00 2001 From: kevto Date: Tue, 6 Jul 2021 19:21:29 +0200 Subject: [PATCH] Fixing bug with input class in ModelBuilder.build(Map) --- pom.xml | 2 +- src/main/java/javax/visrec/ml/model/ModelBuilder.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 5217df4..5f89a6a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 javax.visrec visrec-api - 1.0.4-SNAPSHOT + 1.0.5-SNAPSHOT jar javax.visrec:visrec-api diff --git a/src/main/java/javax/visrec/ml/model/ModelBuilder.java b/src/main/java/javax/visrec/ml/model/ModelBuilder.java index 3758084..bca835a 100644 --- a/src/main/java/javax/visrec/ml/model/ModelBuilder.java +++ b/src/main/java/javax/visrec/ml/model/ModelBuilder.java @@ -28,18 +28,22 @@ public interface ModelBuilder { * @throws javax.visrec.ml.model.ModelCreationException */ default T build(Map configuration) throws ModelCreationException { + ModelBuilder thizz = this; Method[] methods = this.getClass().getDeclaredMethods(); for (Method method : methods) { if (!method.getName().equals("build") && method.getParameterCount() == 1 && configuration.containsKey(method.getName())) { try { - method.invoke(this, configuration.get(method.getName())); + Object obj = method.invoke(thizz, configuration.get(method.getName())); + if (thizz.getClass().isInstance(obj)) { + thizz = (ModelBuilder) thizz.getClass().cast(obj); + } } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) { throw new InvalidConfigurationException("Couldn't invoke '" + method.getName() + "'", e); } } } - return build(); + return thizz.build(); } }