-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DDFFileParser does not handle resource without a data type ("none") #833
Comments
Thx to reporting this. 🙏 I will look at this deeper but at first sight it makes sense. |
I will probably go to What should we do for invalid model (Read resource without datatype). |
There are pretty many places that have
I haven't worked long enough with this code to make an informed answer, but since it's a runtime issue in old code, I would probably be hesitant to start throwing an exception because it would break currently working code (the same argument goes for not skipping the model). Logging an error is probably a good idea, and there could probably be an explicit note around the type property as well: (We came across this behavior by importing the standard XMLs (such as http://www.openmobilealliance.org/release/ObjLwM2M_Server/V1_1_1-20190617-A/OMA-SUP-XML_LWM2M_Server-V1_1_1-20190617-A.xml), and we are using it for the purpose of creating an API/GUI on top of the information from the XML, so the workaround for us is to simply manually edit the relevant, blacklisted resources "by hand" until we can check for this edge case with logic instead.) |
This confirm my choice for 1.0.x but make me hesitate to use Type.NONE for the 1.1 🤔
At DDFFileParser/ResourceModel/ObjectModel should just be able to handle invalid file, this allow the editor/validator use cases. But in a LeshanClient or Server you should use only valid model. |
I am not really sure why there are so many null checks though, since it cannot be null (in the current revision) AFAICT. Goinging over those places could be worth a couple of minutes. Introducing null and attaching meaning to it seems less clear to me than the alternative but it is totally OK.
That makes it sound like the leshan client/servers would need another level of validation/another type (or, more simply, make the editor/validator use cases work with non-resourcemodels and have all constructed ResourceModels be valid). |
I suppose because :
I will do that for sure.
I think it could make sense.
But this will not really fit your usecase or I missed something ? |
I think there is two kind of validation :
|
I made a pretty big mistake and only viewed "usages" in my dependency, not for the whole Leshan suite 🙈 There are indeed many more places that constructs ResourceModel, so null seems correct.
That sounds good to me. |
I create a PR as a fix for the 1.0.x version : #834 |
Thanks for getting back so quickly, both with comments and a fix! I like how you added more validations for the other fields too 👍 |
By the way, as you are using Leshan, could you eventually take time to give us some information about that in : #830 🙏 |
For the future version : #835 |
(fix integrated in master) |
Hi again @sbernard31, I forwarded your request about information for #830 to my employer but it seems like we want to put it on hold for now. I'll keep it in the back of my head. |
Thx for your help :) |
The specifications of both LWM2M 1.0 and 1.1 have normative listings of resources' data type. There's a "none" entry in that listing, which states
When reading resource model definitions using DDFFileParser, and the resource is specified with
<Type></Type>
, that resource model still getsType.STRING
as type.See https://github.com/eclipse/leshan/blob/dea23774923a2abfb09968128802ce3fcde0ab4b/leshan-core/src/main/java/org/eclipse/leshan/core/model/DDFFileParser.java#L134 for the implicit default case, and https://github.com/eclipse/leshan/blob/dea23774923a2abfb09968128802ce3fcde0ab4b/leshan-core/src/main/java/org/eclipse/leshan/core/model/DDFFileParser.java#L158-L180 for the switch case which we "fallthrough" with an empty type.
I would expect either
null
or an explicit sentinel value such asType.NONE
, where the latter is preferred both since it avoids having to null check, and because it's name matches the specification(s).The text was updated successfully, but these errors were encountered: