Bug 5444: Allow null value in config module list setter 33/37433/3
authorAndrej Mak <andmak@cisco.com>
Mon, 11 Apr 2016 11:17:54 +0000 (13:17 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 19 Apr 2016 14:26:40 +0000 (14:26 +0000)
Change-Id: Ibdd8f93d7d8bf213892c1af8632f3ec0989cd617
Signed-off-by: Andrej Mak <andmak@cisco.com>
opendaylight/config/yang-jmx-generator-plugin/src/main/java/org/opendaylight/controller/config/yangjmxgenerator/plugin/ftl/TemplateFactory.java
opendaylight/config/yang-test/src/test/java/org/opendaylight/controller/config/yang/test/impl/NetconfTestImplModuleTest.java

index 999b27fb9198b92df5afb794431d878f428dac2e..4c67a67f42487d337c9ec8de0b42aa0562a93e2a 100644 (file)
@@ -690,8 +690,8 @@ public class TemplateFactory {
 
                 String setterBody = "this." + varName + " = " + varName + ";";
                 if (isListOfDependencies) {
 
                 String setterBody = "this." + varName + " = " + varName + ";";
                 if (isListOfDependencies) {
-                    String nullCheck = String.format("if (%s == null) throw new IllegalArgumentException(\"Null not supported\");%n",
-                            varName);
+                    String nullCheck = String.format("if (%s == null) {\n%s = new java.util.ArrayList<>(); \n}%n",
+                            varName, varName);
                     setterBody = nullCheck + setterBody;
                 }
                 MethodDefinition setter = new MethodDefinition("void",
                     setterBody = nullCheck + setterBody;
                 }
                 MethodDefinition setter = new MethodDefinition("void",
index 680fe5048a8a23568a91df18571f7b84bada52cd..3e0a741076f2e3c80e3b8b5e335484a815fb94a5 100644 (file)
@@ -8,9 +8,7 @@
 package org.opendaylight.controller.config.yang.test.impl;
 
 import static org.junit.Assert.assertEquals;
 package org.opendaylight.controller.config.yang.test.impl;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 import static org.mockito.Mockito.doReturn;
 
 import com.google.common.collect.Lists;
 import static org.mockito.Mockito.doReturn;
 
 import com.google.common.collect.Lists;
@@ -112,15 +110,8 @@ public class NetconfTestImplModuleTest  extends AbstractConfigTest {
 
         ObjectName on = createInstance(transaction, instanceName, 4);
         NetconfTestImplModuleMXBean proxy = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class);
 
         ObjectName on = createInstance(transaction, instanceName, 4);
         NetconfTestImplModuleMXBean proxy = transaction.newMXBeanProxy(on, NetconfTestImplModuleMXBean.class);
-        try{
-            proxy.setTestingDeps(null);
-            fail();
-        }catch(RuntimeException e) {
-            Throwable cause = e.getCause();
-            assertNotNull(cause);
-            assertTrue("Invalid type " + cause, cause instanceof IllegalArgumentException);
-            assertEquals("Null not supported", cause.getMessage());
-        }
+        proxy.setTestingDeps(null);
+        assertTrue(proxy.getTestingDeps().isEmpty());
         proxy.setTestingDeps(Collections.<ObjectName>emptyList());
     }
 
         proxy.setTestingDeps(Collections.<ObjectName>emptyList());
     }