[MDSAL-664] Binding codegen generates invalid enforcer for String/length Created: 24/May/21  Updated: 31/May/21  Resolved: 24/May/21

Status: Resolved
Project: mdsal
Component/s: Binding codegen
Affects Version/s: None
Fix Version/s: 8.0.0, 7.0.8, 6.0.11

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


 Description   

The following model

module foo {
  namespace foo;
  prefix foo;

  list string {
    leaf name {
      type string {
        length 1..32;
      }
    }
  }
}

generates code which does not compile because:

[target/test/src/mdsalXXX/org/opendaylight/yang/gen/v1/foo/norev/StringBuilder.java:99: error: cannot find symbol
        final int length = value.codePointCount(0, value.length());
                                                        ^
  symbol:   method length()
  location: variable value of type org.opendaylight.yang.gen.v1.foo.norev.String, target/test/src/mdsalXXX/org/opendaylight/yang/gen/v1/foo/norev/StringBuilder.java:108: error: incompatible types: java.lang.String cannot be converted to org.opendaylight.yang.gen.v1.foo.norev.String
            check_nameLength(value);
                             ^, Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output]


 Comments   
Comment by Robert Varga [ 31/May/21 ]

This is caused by a hard-coded unqualified reference to java.lang.String, which is being shadowed by the context – 'String' ends up referring to the generated foo.norev.String – and hence we get incompatible type references and a reference to non-existing foo.norev.String.length() method.

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