[YANGTOOLS-335] Potentional bug: AbstractGeneratedTypeBuilder allows multiple addition of elements witch equals Created: 10/Oct/14  Updated: 10/Apr/22  Resolved: 20/Oct/14

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Peter Kajsa Assignee: Peter Kajsa
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 2172

 Description   

Potentional bug: AbstractGeneratedTypeBuilder allows multiple addition (via add* methods) of elements witch equals. Check of duplicity of added elements is missing in add* methods of AbstractGeneratedTypeBuilder and subclass GeneratedTypeBuilderImpl.

For an example, it is possible to add two constants with the same type, name and value:

GeneratedTypeBuilder generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package","MyName");

Constant constant1 = generatedTypeBuilder.addConstant(Types.typeForClass(String.class), "myConstant", "myConstantValue");

Constant constant2 = generatedTypeBuilder.addConstant(Types.typeForClass(String.class), "myConstant", "myConstantValue");

constant2 != null //true, constant2 is not null
constant2 != constant1 //true, constant2 is a reference to new object
constant2.equals(constant1); // true, constant1 and constant2 are equal (they have the same name, type and value)

generatedTypeBuilder.toInstance().getConstantDefinitions().size() //2

The same behavior is present also in other add* methods.

Notice: Maybe this is not a bug and the check is performed somewhere else just before generation of source code from these objects.



 Comments   
Comment by Peter Kajsa [ 17/Oct/14 ]

patch set: https://git.opendaylight.org/gerrit/#/c/12042/1

Generated at Wed Feb 07 20:52:55 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.