Uploaded image for project: 'yangtools'
  1. yangtools
  2. YANGTOOLS-186

Odd use of number constructors in generated code

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Resolution: Duplicate
    • None
    • None
    • None
    • None
    • Operating System: Linux
      Platform: PC

    • 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;
      }

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Unassigned Unassigned
              readams Rob Adams
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: