Skip to content

Commit

Permalink
Fix UWF_UNWRITTEN_FIELD spotbugs warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Mi-La committed Dec 11, 2023
1 parent ab239be commit e082d67
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 25 deletions.
14 changes: 11 additions & 3 deletions compiler/extensions/java/freemarker/Choice.java.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -286,21 +286,27 @@ ${I}break;
@Override
public boolean equals(java.lang.Object obj)
{
<#if compoundParametersData.list?has_content || fieldList?has_content>
if (obj instanceof ${name})
{
final ${name} that = (${name})obj;

return
<#list compoundParametersData.list as parameter>
<@compound_compare_parameter parameter/> &&
</#list>
<#list compoundParametersData.list as parameter>
<@compound_compare_parameter parameter/><#if parameter_has_next || fieldList?has_content> &&<#else>;</#if>
</#list>
<#if fieldList?has_content>
(
(objectChoice == null && that.objectChoice == null) ||
(objectChoice != null && objectChoice.equals(that.objectChoice))
);
</#if>
}

return false;
<#else>
return obj instanceof ${name};
</#if>
}

<#macro choice_hash_code_no_match name indent>
Expand Down Expand Up @@ -493,5 +499,7 @@ ${I}break;
</#list>

<@compound_parameter_members compoundParametersData/>
<#if fieldList?has_content>
private java.lang.Object objectChoice;
</#if>
}
16 changes: 12 additions & 4 deletions compiler/extensions/java/freemarker/Union.java.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,28 @@ public class ${name} implements <#rt>
@Override
public boolean equals(java.lang.Object obj)
{
<#if compoundParametersData.list?has_content || fieldList?has_content>
if (obj instanceof ${name})
{
final ${name} that = (${name})obj;

return
<#list compoundParametersData.list as parameter>
<@compound_compare_parameter parameter/> &&
</#list>
<#list compoundParametersData.list as parameter>
<@compound_compare_parameter parameter/><#if parameter_has_next || fieldList?has_content> &&<#else>;</#if>
</#list>
<#if fieldList?has_content>
choiceTag == that.choiceTag &&
(
(objectChoice == null && that.objectChoice == null) ||
(objectChoice != null && objectChoice.equals(that.objectChoice))
);
</#if>
}

return false;
<#else>
return obj instanceof ${name};
</#if>
}

@Override
Expand Down Expand Up @@ -434,6 +440,8 @@ public class ${name} implements <#rt>
</#list>

<@compound_parameter_members compoundParametersData/>
private java.lang.Object objectChoice;
private int choiceTag = UNDEFINED_CHOICE;
<#if fieldList?has_content>
private java.lang.Object objectChoice;
</#if>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package zserio.extension.java;

import zserio.ast.EnumItem;
import zserio.ast.EnumType;
import zserio.ast.ZserioType;

Expand Down
4 changes: 0 additions & 4 deletions scripts/test_zs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ EOF
<Match>
<!-- Be wary of letting constructors throw exceptions - Should be fixed in generated code. -->
<Bug code="CT"/>
</Match>
<Match>
<!-- Unwritten field - Should be fixed in generated code. -->
<Bug code="UwF"/>
</Match>${SPOTBUGS_FILTER_SQLITE}
</FindBugsFilter>
EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import array_types.packed_auto_array_removed_enum_item.Traffic;

import zserio.runtime.ZserioError;
import zserio.runtime.io.BitBuffer;
import zserio.runtime.io.SerializeUtil;

public class PackedAutoArrayRemovedEnumItemTest
Expand Down
4 changes: 0 additions & 4 deletions test/language/array_types/spotbugs_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@
<!-- Be wary of letting constructors throw exceptions - Should be fixed in generated code. -->
<Bug code="CT"/>
</Match>
<Match>
<!-- Unwritten field - Should be fixed in generated code. -->
<Bug code="UwF"/>
</Match>
</FindBugsFilter>
4 changes: 0 additions & 4 deletions test/language/choice_types/spotbugs_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@
<!-- Be wary of letting constructors throw exceptions - Should be fixed in generated code. -->
<Bug code="CT"/>
</Match>
<Match>
<!-- Unwritten field - Should be fixed in generated code. -->
<Bug code="UwF"/>
</Match>
</FindBugsFilter>
4 changes: 0 additions & 4 deletions test/language/union_types/spotbugs_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@
<!-- Be wary of letting constructors throw exceptions - Should be fixed in generated code. -->
<Bug code="CT"/>
</Match>
<Match>
<!-- Unwritten field - Should be fixed in generated code. -->
<Bug code="UwF"/>
</Match>
</FindBugsFilter>

0 comments on commit e082d67

Please sign in to comment.