[MDSAL-792] Union value classes need to enforce non-null components Created: 09/Nov/22  Updated: 09/Nov/22  Resolved: 09/Nov/22

Status: Resolved
Project: mdsal
Component/s: Binding codegen
Affects Version/s: None
Fix Version/s: 11.0.0, 10.0.4

Type: Improvement Priority: Medium
Reporter: Robert Varga Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

We have the following code generated here:

        public VlanId(Id _id) {
            super();
            this._id = _id;
            this._enumeration = null;
        }
        
        public VlanId(Enumeration _enumeration) {
            super();
            this._enumeration = _enumeration;
            this._id = null;
        }

in org.opendaylight.yang.gen.v1.urn.test.rev170101.Cont.java.

This works in general, but it allows invalid objects to be created – if the argument is null, we end up with a union which is neither one or the other:

        public VlanId(Id _id) {
            super();
            this._id = Objects.requireNonNull(_id);
            this._enumeration = null;
        }
        
        public VlanId(Enumeration _enumeration) {
            super();
            this._enumeration = Objects.requireNonNull(_enumeration);
            this._id = null;
        } 

 


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