[YANGTOOLS-461] NPE in a setter method for a length-restricted string. Created: 09/Jun/15  Updated: 10/Apr/22  Resolved: 09/Jun/15

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

Type: Bug
Reporter: Shigeru Yasuda Assignee: Unassigned
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: 3643

 Description   

The following patch changed behavior of builder class generated by yangtools.

commit 7998081d8e1761bf4798c1642e8e6107fc4666fc
Author: Robert Varga <rovarga@cisco.com>
Date: Sun May 31 19:51:43 2015 +0200

BUG-1485: convert BuilderTemplate to use LengthGenerator

Before that patch was merged, a setter method for a length-restricted string accepts a null string.

YANG model:
container test {
leaf name {
type string

{ length "1 .. 31"; }

}
}

Setter method in a builder class:
public TestBuilder setName(java.lang.String value) {
if (value != null) {
BigInteger _constraint = BigInteger.valueOf(value.length());
boolean isValidLength = false;
for (Range<BigInteger> r : _name_length()) {
if (r.contains(_constraint))

{ isValidLength = true; }

}
if (!isValidLength)

{ throw new IllegalArgumentException(String.format("Invalid length: %s, expected: %s.", value, _name_length)); }

}
this._name = value;
return this;
}

But after that patch was merged, a setter method for a length-restricted string causes NPE when a null string is passed.

private static void check_nameLength(final String value) {
final int length = value.length(); <=== NPE if value is null
if (length >= 1 && length <= 31)

{ return; }

throw new IllegalArgumentException(String.format("Invalid length: %s, expected: [[1‥31]].", value));
}

public TestBuilder setName(java.lang.String value)

{ check_nameLength(value); this._name = value; return this; }

I think a setter method should accept a null string even if a length restriction is applied.



 Comments   
Comment by Colin Dixon [ 09/Jun/15 ]

Tony says it should be fixed by: https://git.opendaylight.org/gerrit/#/c/22189/

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