File tree Expand file tree Collapse file tree
main/java/com/mbed/coap/packet
test/java/com/mbed/coap/packet Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/*
2- * Copyright (C) 2022-2025 java-coap contributors (https://github.com/open-coap/java-coap)
2+ * Copyright (C) 2022-2026 java-coap contributors (https://github.com/open-coap/java-coap)
33 * Copyright (C) 2011-2021 ARM Limited. All rights reserved.
44 * SPDX-License-Identifier: Apache-2.0
55 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -133,7 +133,7 @@ protected boolean parseOption(int type, Opaque data) {
133133 * @return byte array value or null if does not exist
134134 */
135135 public Opaque getCustomOption (Integer optNumber ) {
136- if (!unrecognizedOptions .containsKey (optNumber )) {
136+ if (unrecognizedOptions == null || !unrecognizedOptions .containsKey (optNumber )) {
137137 return null ;
138138 }
139139 return unrecognizedOptions .get (optNumber ).getFirstValue ();
Original file line number Diff line number Diff line change 11/*
2- * Copyright (C) 2022-2025 java-coap contributors (https://github.com/open-coap/java-coap)
2+ * Copyright (C) 2022-2026 java-coap contributors (https://github.com/open-coap/java-coap)
33 * Copyright (C) 2011-2021 ARM Limited. All rights reserved.
44 * SPDX-License-Identifier: Apache-2.0
55 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -533,6 +533,13 @@ void correlationOptionShouldBeElectiveAndSafeToForward() {
533533 assertFalse (hasNoCacheKey (HeaderOptions .OPEN_COAP_CORRELATION_TAG ));
534534 }
535535
536+ @ Test
537+ void getCustomOption_shouldReturnNull_whenNoCustomOptionsSet () {
538+ BasicHeaderOptions hdr = new BasicHeaderOptions ();
539+
540+ assertNull (hdr .getCustomOption (100 ));
541+ }
542+
536543 private static byte [] serialize (BasicHeaderOptions hdr ) throws IOException , CoapException {
537544 ByteArrayOutputStream baos = new ByteArrayOutputStream ();
538545 hdr .serialize (baos );
You can’t perform that action at this time.
0 commit comments