Add serialVersionUID fields
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DatastoreContextIntrospector.java
index 0ee005a708c8d4c660ee3df2980b08045bb964d6..d9445f18a1cc237a61376fffcd92d87d20735628 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Optional;
 import java.util.Set;
 import java.util.function.Function;
 import javax.management.ConstructorParameters;
@@ -84,7 +83,7 @@ public class DatastoreContextIntrospector {
     private static void introspectPrimitiveTypes() {
         final Set<Class<?>> primitives = ImmutableSet.<Class<?>>builder().addAll(
                 Primitives.allWrapperTypes()).add(String.class).build();
-        for (final Class<?> primitive: primitives) {
+        for (final Class<?> primitive : primitives) {
             try {
                 processPropertyType(primitive);
             } catch (final NoSuchMethodException e) {
@@ -175,7 +174,7 @@ public class DatastoreContextIntrospector {
             // This must be a yang-defined type. We need to find the constructor that takes a
             // primitive as the only argument. This will be used to construct instances to perform
             // validation (eg range checking). The yang-generated types have a couple single-argument
-            // constructors but the one we want has the bean ConstructorProperties annotation.
+            // constructors but the one we want has the ConstructorParameters annotation.
             for (final Constructor<?> ctor: propertyType.getConstructors()) {
                 final ConstructorParameters ctorParAnnotation = ctor.getAnnotation(ConstructorParameters.class);
                 if (ctor.getParameterCount() == 1 && ctorParAnnotation != null) {
@@ -382,9 +381,8 @@ public class DatastoreContextIntrospector {
         if (propertyType.isEnum()) {
             try {
                 final Method enumConstructor = propertyType.getDeclaredMethod("forName", String.class);
-                final Object optional =  enumConstructor.invoke(null, from.toString().toLowerCase(Locale.ROOT));
-                if (optional instanceof Optional) {
-                    return ((Optional<Object>)optional).orElseThrow();
+                if (enumConstructor.getReturnType().equals(propertyType)) {
+                    return enumConstructor.invoke(null, from.toString().toLowerCase(Locale.ROOT));
                 }
             } catch (NoSuchMethodException e) {
                 LOG.error("Error constructing value ({}) for enum {}", from, propertyType);