You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/02/25 22:37:26 UTC

[plc4x] 01/04: - Made the ConfigurationFactory check the generic type before injecting the configuration

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch feature/driver-testsuite
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit bdf10cc8bfe593b28f9fb3f5b54b842d8bcbeff7
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Feb 25 23:31:36 2020 +0100

    - Made the ConfigurationFactory check the generic type before injecting the configuration
---
 .../plc4x/java/spi/configuration/ConfigurationFactory.java     | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationFactory.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationFactory.java
index 668e830..832b9db 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationFactory.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/configuration/ConfigurationFactory.java
@@ -33,6 +33,7 @@ import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
 import java.net.URLDecoder;
 import java.util.*;
 import java.util.function.Function;
@@ -134,7 +135,14 @@ public class ConfigurationFactory {
                 .filter(type -> type.getRawType().equals(HasConfiguration.class))
                 .findAny();
             if (typeOptional.isPresent()) {
-                ((HasConfiguration) obj).setConfiguration(configuration);
+                final ParameterizedType parameterizedType = typeOptional.get();
+                final Type configType = parameterizedType.getActualTypeArguments()[0];
+                if(configType instanceof Class) {
+                    Class<?> configClass = (Class<?>) configType;
+                    if(configClass.isAssignableFrom(configuration.getClass())) {
+                        ((HasConfiguration) obj).setConfiguration(configuration);
+                    }
+                }
             }
 
         }