Bug 1434 - Make arrays non-mutable
[yangtools.git] / code-generator / binding-java-api-generator / src / main / java / org / opendaylight / yangtools / sal / java / api / generator / UnionTemplate.xtend
index 2b56179964c464b17ec2259dd5a4835a14d32d4d..ecaaf8af01510af20257ba4a72e22ef20d8c7767 100644 (file)
@@ -52,7 +52,11 @@ class UnionTemplate extends ClassTemplate {
                     «type.name» defInst = «type.name»Builder.getDefaultInstance(defVal);
                     «FOR other : finalProperties»
                         «IF other.name.equals("value")»
+                            «IF other.returnType.importedName.contains("[]")»
+                            this.«other.fieldName» = Arrays.copyOf(«other.fieldName», «other.fieldName».length);
+                            «ELSE»
                             this.«other.fieldName» = «other.fieldName»;
+                            «ENDIF»
                         «ELSE»
                             this.«other.fieldName» = defInst.«other.fieldName»;
                         «ENDIF»
@@ -121,7 +125,11 @@ class UnionTemplate extends ClassTemplate {
             «ENDIF»
             «IF !properties.empty»
                 «FOR p : properties»
+                    «IF p.returnType.importedName.contains("[]")»
+                    this.«p.fieldName» = Arrays.copyOf(source.«p.fieldName», source.«p.fieldName».length);
+                    «ELSE»
                     this.«p.fieldName» = source.«p.fieldName»;
+                    «ENDIF»
                 «ENDFOR»
             «ENDIF»
         }