[YANGTOOLS-214] toString methods in generated classes should use getClass().getSimpleName() Created: 15/Jul/14 Updated: 10/Apr/22 Due: 25/Jul/14 Resolved: 13/Aug/14 |
|
| Status: | Resolved |
| Project: | yangtools |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | ||
| Reporter: | Devin Avery | Assignee: | Ladislav Borak |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Operating System: Mac OS |
||
| 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" ); OutputAction build1 = new OutputActionBuilder() // OutputAction build2 = new OutputActionBuilder() // assertFalse( build1.equals( build2 ) ); //this returns false 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. |
| Comments |
| Comment by Ladislav Borak [ 28/Jul/14 ] |
|
proposed patch: https://git.opendaylight.org/gerrit/#/c/9364/ |