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 2022/01/28 10:47:36 UTC

[plc4x] branch develop updated: URLDecoder.decode compatible with JDK 8 (#307)

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

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 24ce0a6  URLDecoder.decode compatible with JDK 8 (#307)
24ce0a6 is described below

commit 24ce0a66a629606cf90ba46b013980f74d454db5
Author: Yang Lin <to...@gmail.com>
AuthorDate: Fri Jan 28 18:47:30 2022 +0800

    URLDecoder.decode compatible with JDK 8 (#307)
    
    * Compatible with JDK 8
    
    * Add catch
---
 .../apache/plc4x/java/spi/configuration/ConfigurationFactory.java    | 5 ++++-
 1 file changed, 4 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 ed30f4d..4bd2456 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
@@ -24,6 +24,7 @@ import org.apache.commons.lang3.reflect.FieldUtils;
 import org.apache.plc4x.java.spi.configuration.annotations.*;
 import org.apache.plc4x.java.spi.configuration.annotations.defaults.*;
 
+import java.io.UnsupportedEncodingException;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.ParameterizedType;
@@ -87,7 +88,7 @@ public class ConfigurationFactory {
                 if (paramStringValues.containsKey(configName)) {
                     String stringValue = paramStringValues.get(configName).get(0);
                     // As the arguments might be URL encoded, be sure it's decoded.
-                    stringValue = URLDecoder.decode(stringValue, StandardCharsets.UTF_8);
+                    stringValue = URLDecoder.decode(stringValue, "UTF-8");
                     FieldUtils.writeField(instance, field.getName(), toFieldValue(field, stringValue), true);
                     missingFieldNames.remove(configName);
                 } else {
@@ -106,6 +107,8 @@ public class ConfigurationFactory {
             }
         } catch (IllegalAccessException e) {
             throw new IllegalArgumentException("Unable to access all fields from Configuration Class '" + pClazz.getSimpleName() + "'", e);
+        } catch (UnsupportedEncodingException e) {
+            throw new IllegalArgumentException("Unsupported encoding");
         }
         return instance;
     }