From: Marek Gradzki Date: Tue, 25 Oct 2016 05:57:30 +0000 (+0200) Subject: Improve equals generation for jvpp DTOs X-Git-Tag: v17.01-rc0~52 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=af0c70cf764f7b027102b7e5e89f8c34436b5f22;p=vpp.git Improve equals generation for jvpp DTOs Variable 'other' is no longer defined in equals method of DTOs without defined fileds. Fixes dead local store coverity issues. Change-Id: I69eddf2b4b3f433149ff4d49e49c46515572d61a Signed-off-by: Marek Gradzki --- diff --git a/vpp-api/java/jvpp/gen/jvppgen/dto_gen.py b/vpp-api/java/jvpp/gen/jvppgen/dto_gen.py index b117288cdd2..12354793bf7 100644 --- a/vpp-api/java/jvpp/gen/jvppgen/dto_gen.py +++ b/vpp-api/java/jvpp/gen/jvppgen/dto_gen.py @@ -150,7 +150,9 @@ def generate_dto_tostring(camel_case_dto_name, func): return tostring_template.substitute(cls_name=camel_case_dto_name, fields_tostring=tostring_fields[:-8]) - +equals_other_template = Template(""" + final $cls_name other = ($cls_name) o; +\n""") equals_field_template = Template(""" if (!java.util.Objects.equals(this.$field_name, other.$field_name)) { return false; }\n""") @@ -165,9 +167,6 @@ equals_template = Template(""" @Override if (o == null || getClass() != o.getClass()) { return false; } - - final $cls_name other = ($cls_name) o; - $comparisons return true; }\n\n""") @@ -187,8 +186,10 @@ def generate_dto_equals(camel_case_dto_name, func): else: equals_fields += equals_field_template.substitute(field_name=field_name) - return equals_template.substitute(cls_name=camel_case_dto_name, - comparisons=equals_fields) + if equals_fields != "": + equals_fields = equals_other_template.substitute(cls_name=camel_case_dto_name) + equals_fields + + return equals_template.substitute(comparisons=equals_fields) hash_template = Template(""" @Override