Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2025 java-coap contributors (https://github.com/open-coap/java-coap)
* Copyright (C) 2022-2026 java-coap contributors (https://github.com/open-coap/java-coap)
* Copyright (C) 2011-2021 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -133,7 +133,7 @@ protected boolean parseOption(int type, Opaque data) {
* @return byte array value or null if does not exist
*/
public Opaque getCustomOption(Integer optNumber) {
if (!unrecognizedOptions.containsKey(optNumber)) {
if (unrecognizedOptions == null || !unrecognizedOptions.containsKey(optNumber)) {
return null;
}
return unrecognizedOptions.get(optNumber).getFirstValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022-2025 java-coap contributors (https://github.com/open-coap/java-coap)
* Copyright (C) 2022-2026 java-coap contributors (https://github.com/open-coap/java-coap)
* Copyright (C) 2011-2021 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -533,6 +533,13 @@ void correlationOptionShouldBeElectiveAndSafeToForward() {
assertFalse(hasNoCacheKey(HeaderOptions.OPEN_COAP_CORRELATION_TAG));
}

@Test
void getCustomOption_shouldReturnNull_whenNoCustomOptionsSet() {
BasicHeaderOptions hdr = new BasicHeaderOptions();

assertNull(hdr.getCustomOption(100));
}

private static byte[] serialize(BasicHeaderOptions hdr) throws IOException, CoapException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hdr.serialize(baos);
Expand Down
Loading