okleine / nCoAP

Java implementation of the CoAP protocol using netty
BSD 3-Clause "New" or "Revised" License
179 stars 57 forks source link

Option.createTargetURIOptions() error when path is missing #8

Closed stefanhueske closed 12 years ago

stefanhueske commented 12 years ago
Option.createTargetURIOptions(new URI("coap://[2001:db8::2:1]")); 
//and "coap://[2001:db8::2:1]/" also

throws

[StringOption] Value length for URI_PATH option must be between 1 and 270 but is 0
de.uniluebeck.itm.spitfire.nCoap.message.options.InvalidOptionException: [StringOption] Value length for URI_PATH option must be between 1 and 270 but is 0
    at de.uniluebeck.itm.spitfire.nCoap.message.options.StringOption.setValue(StringOption.java:52)
    at de.uniluebeck.itm.spitfire.nCoap.message.options.StringOption.<init>(StringOption.java:37)
    at de.uniluebeck.itm.spitfire.nCoap.message.options.Option.createSeparatedOptions(Option.java:327)
    at de.uniluebeck.itm.spitfire.nCoap.message.options.Option.createTargetURIOptions(Option.java:119)
    at de.uniluebeck.itm.spitfire.nCoap.message.options.OptionTest$UriEncodeTest.test(OptionTest.java:52)
    at de.uniluebeck.itm.spitfire.nCoap.message.options.OptionTest.testCreateTargetURIOptions(OptionTest.java:30)

Cause:

        String path = uri.getRawPath();
        if(path != null){ 
            // [...]
            result.addAll(createSeparatedOptions(OptionName.URI_PATH, "/", path));
        }