[MDSAL-355]  IdentifiableItemCodec should ignore case when sorting keys Created: 22/Jun/18  Updated: 09/Oct/18  Resolved: 09/Oct/18

Status: Resolved
Project: mdsal
Component/s: Binding runtime
Affects Version/s: None
Fix Version/s: Fluorine SR1, Oxygen SR4, 3.0.1

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


 Description   

Input parameter sequence of constructor of generated type or builder follows alphabetical and case-insensitive order, which differs with IdentifiableItemCodec expectation.

 

IdentifiableItemCodec.java: 

(q1, q2) -> q1.getLocalName().compareTo*IgnoreCase*(q2.getLocalName()

 

ClassTempate.xtend:

Collections.sort(sorted, [p1, p2|
p1.name.compareTo(p2.name)
]);

 

BuilderTemplate.xtend

«Collections.sort(keyProps,
[ p1, p2 |
return p1.name.compareTo(p2.name)
])
»

 



 Comments   
Comment by Robert Varga [ 22/Jun/18 ]

Key properties names are not QName.localNames. Is there a testcase which does currently work?

Comment by Huafei Zhang [ 26/Jun/18 ]

It's hard to provide an existing test case. We found this issue in our controller application.
we have a list with a composite key

 

list OspfStatLsdbBrief {
    key "AreaIndex LsaType LsId AdvRtr";
    leaf AreaIndex { type int32; description "Area Index"; }
    leaf LsaType { type uint8; description "LSA Type"; }
    leaf LsId { type int32; description "LSA ID"; }
    leaf AdvRtr { type string; description "Advertised Router"; }
}

when decode a list entry accessing YangInstanceIdentifier by calling method "InstanceIdentifier<?> fromYangInstanceIdentifier(@Nonnull YangInstanceIdentifier dom)" of service

<reference id="mappingCodec"
interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer"/>

an java.lang.ClassCastException thrown:

----------------------------------------------------------------------------------------------------------------------------------------------------------------

java.lang.ClassCastException: Cannot cast java.lang.Integer to java.lang.Short
at java.lang.invoke.MethodHandleImpl.newClassCastException(MethodHandleImpl.java:361)
at java.lang.invoke.MethodHandleImpl.castReference(MethodHandleImpl.java:356)
at org.opendaylight.yangtools.binding.data.codec.impl.IdentifiableItemCodec.deserialize(IdentifiableItemCodec.java:100)
at org.opendaylight.yangtools.binding.data.codec.impl.IdentifiableItemCodec.deserialize(IdentifiableItemCodec.java:30)
at org.opendaylight.yangtools.binding.data.codec.impl.KeyedListNodeCodecContext.getBindingPathArgument(KeyedListNodeCodecContext.java:73)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingCodecContext.getCodecContextNode(BindingCodecContext.java:169)
at org.opendaylight.yangtools.binding.data.codec.impl.InstanceIdentifierCodec.deserialize(InstanceIdentifierCodec.java:36)
at org.opendaylight.yangtools.binding.data.codec.impl.InstanceIdentifierCodec.deserialize(InstanceIdentifierCodec.java:19)
at org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry.fromYangInstanceIdentifier(BindingNormalizedNodeCodecRegistry.java:92)
at org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec.fromYangInstanceIdentifier(BindingToNormalizedNodeCodec.java:171)
at Proxy995bc85b_803c_4f1a_9934_7430940d1b66.fromYangInstanceIdentifier(Unknown Source)
at com.utstar.qx.sal.connect.qx.util.QxBaseOps.get(QxBaseOps.java:166)

---------------------------------------------------------------------------------------------------------------------------------------------------------

This is because the constructor parameter from instance identifier is injected with wrong order.

Fixing code of either xxtemplate.xtend or IdentifiableItemCodec will work.

Comment by Robert Varga [ 04/Oct/18 ]

I see – the problem is that "LsId" and "LsaType" compare differently. This usually does not happen, as standard models usually end up using capitalization from the use of dashes, which is what the comparison was designed to overcome. Alas the shortcut does not work, as we really need to enlist binding-generator types and use them to establish the order arguments.

Comment by Robert Varga [ 04/Oct/18 ]

zhfinder does https://git.opendaylight.org/gerrit/76650 fix the issue for you?

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