Merge "BUG-2606: formalize the augmentation removal"
authorTony Tkacik <ttkacik@cisco.com>
Tue, 20 Jan 2015 09:39:18 +0000 (09:39 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 20 Jan 2015 09:39:18 +0000 (09:39 +0000)
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/util/AugmentableDispatchSerializer.java
common/parent/pom.xml

index 38b4e8b211e00cb181e246623928dff4b2de32b6..b0860eb335108a993a7f9c21d7ff21e25a768af3 100644 (file)
@@ -8,14 +8,12 @@
 package org.opendaylight.yangtools.binding.data.codec.util;
 
 import com.google.common.base.Preconditions;
-
 import java.io.IOException;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Map.Entry;
-
 import org.opendaylight.yangtools.yang.binding.Augmentable;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter;
@@ -49,14 +47,14 @@ public class AugmentableDispatchSerializer implements DataObjectSerializerImplem
             } else {
                 augmentations = BindingReflections.getAugmentations((Augmentable<?>) obj);
             }
-            for (Entry<Class<? extends Augmentation<?>>, Augmentation<?>> aug : augmentations.entrySet()) {
+            for (final Entry<Class<? extends Augmentation<?>>, Augmentation<?>> aug : augmentations.entrySet()) {
                 emitAugmentation(aug.getKey(), aug.getValue(), stream, reg);
             }
         }
     }
 
     private Map<Class<? extends Augmentation<?>>, Augmentation<?>> getFromProxy(final DataObject obj) {
-        InvocationHandler proxy = Proxy.getInvocationHandler(obj);
+        final InvocationHandler proxy = Proxy.getInvocationHandler(obj);
         if (proxy instanceof AugmentationReader) {
             return ((AugmentationReader) proxy).getAugmentations(obj);
         }
@@ -66,9 +64,17 @@ public class AugmentableDispatchSerializer implements DataObjectSerializerImplem
     @SuppressWarnings("rawtypes")
     private void emitAugmentation(final Class type, final Augmentation<?> value, final BindingStreamEventWriter stream,
             final DataObjectSerializerRegistry registry) throws IOException {
+        /*
+         * Binding Specification allowed to insert augmentation with null for
+         * value, which effectively could be used to remove augmentation
+         * from builder / DTO.
+         */
+        if(value == null) {
+            return;
+        }
         Preconditions.checkArgument(value instanceof DataObject);
         @SuppressWarnings("unchecked")
-        DataObjectSerializer serializer = registry.getSerializer(type);
+        final DataObjectSerializer serializer = registry.getSerializer(type);
         if (serializer != null) {
             serializer.serialize((DataObject) value, stream);
         } else {
index 1e2803c655b5fa91f98274050dc18f5d2a16cd41..a2fa60ee4393d3a59cefdb7d630857e892abe857 100644 (file)
@@ -36,7 +36,6 @@
         <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
         <sonar.jacoco.reportPath>target/code-coverage/jacoco.exec</sonar.jacoco.reportPath>
         <sonar.jacoco.itReportPath>target/code-coverage/jacoco-it.exec</sonar.jacoco.itReportPath>
-        <sonar.profile>Sonar way with Findbugs</sonar.profile>
     </properties>
 
     <dependencyManagement>
 
 
     <!-- Note: we can not use variables for these URLs because we need to
-         be able to download the parent pom from the repository the first 
+         be able to download the parent pom from the repository the first
          time we go to use it (since it is in a different project).
          To override the settings, use the "mirror" section of the
          settings.xml. See http://maven.apache.org/settings.html -->