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

toString methods in generated classes should use getClass().getSimpleName()

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • Resolution: Done
    • None
    • None
    • None
    • None
    • Operating System: Mac OS
      Platform: PC

    Description

      I spent about an hour debugging an equality problem where DataObject had the same logical data, but the class types were different and thus equality was failing. Specifically, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri class in its toString method hard-codes the name "Uri". This is fine, except the derived classes do not override the toString method, so when they print out they still print "URI: ..".

      This becomes a problem because the equals() method of URI check class types. So when for example you are comparing two org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction which were built with a URI and another built with a NodeConnector, you will get an equality failure( because URI != NodeConnectorId) and you get no indication via debug that anything is different.

      For example:

      InstanceIdentifier<NodeConnector> instanceId = InstanceIdentifierUtils.createNodeConnectorIdentifier("openflow:1", "3" );
      NodeConnectorRef destPort = new NodeConnectorRef( instanceId );
      NodeConnectorId destPortUri = destPort.getValue().firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId();

      OutputAction build1 = new OutputActionBuilder() //
      .setOutputNodeConnector( new Uri( destPortUri ) ) //
      .build();

      OutputAction build2 = new OutputActionBuilder() //
      .setOutputNodeConnector( destPortUri ) //
      .build();

      assertFalse( build1.equals( build2 ) ); //this returns false
      assertFalse( build1.toString(), build2.toString() ); //this returns true!

      Suggested Solution:

      I understand the argument to have NodeConnectorId( "1" ) != Uri("1"), but we need to be consistent in our toStrings then. The base class "Uri" should really use "getClass().getSimpleName()" - that way the toStrings would not be equal and we can quickly identify the discrepancy.

      Attachments

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

        Activity

          People

            lborak@cisco.com Ladislav Borak
            devin.avery@brocade.com Devin Avery
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: