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

NPE in a setter method for a length-restricted string.

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Resolution: Done
    • None
    • None
    • None
    • None
    • Operating System: All
      Platform: All

    • 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.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            yasuda Shigeru Yasuda
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: