[YANGTOOLS-186] Odd use of number constructors in generated code Created: 12/Jun/14  Updated: 10/Apr/22  Resolved: 13/Jun/14

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

Type: Bug
Reporter: Rob Adams Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Linux
Platform: PC


Issue Links:
Duplicate
duplicates YANGTOOLS-177 Optimize generated range checks Resolved
External issue ID: 1194

 Description   

We're calling things like new Long("1") with a string constant. Here we should use Long.valueOf(1L) rather than calling the constructor, and we shouldn't use a string we should use a constant. At a minimum this should be Long.valueOf("1") if somehow we can't properly generate the constant value.

Here's something that shows up in some generated code:

public static List<Range<Long>> length()

{ final List<Range<Long>> result = new ArrayList<>(); result.add(Range.closed(new Long("1"), new Long("4096"))); return result; }

Here's another example:
public RuleBuilder setOrder(Integer value) {
if (value != null) {
boolean isValidRange = false;
List<Range<Integer>> rangeConstraints = new ArrayList<>();
rangeConstraints.add(Range.closed(new Integer("0"), new Integer("2147483647")));
for (Range<Integer> r : rangeConstraints) {
if (r.contains(value))

{ isValidRange = true; }

}
if (!isValidRange)

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

}

this._order = value;
return this;
}



 Comments   
Comment by Martin Vitez [ 13/Jun/14 ]

This looks like duplicate of YANGTOOLS-177. Patch was already proposed and currently is waiting for review.

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