Skip to content
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

Fix NPE when creating Composite failure Response #1676

Merged
merged 1 commit into from
Nov 21, 2024
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
Expand Up @@ -76,14 +76,15 @@ public ReadCompositeResponse(ResponseCode responseCode, Map<LwM2mPath, LwM2mNode
}
} else {
// handle if content (not timestamped) value is passed
this.timestampedValues = null;
this.content = content;
}

if (ResponseCode.CONTENT.equals(code)) {
// check content is not null
if (content == null) {
if (this.content == null) {
throw new IllegalArgumentException("content OR timestampedValue should be not null");
}

this.timestampedValues = null;
this.content = content;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2024 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Michał Wadowski (Orange) - Add Observe-Composite feature.
*******************************************************************************/
package org.eclipse.leshan.core.response;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.eclipse.leshan.core.ResponseCode;
import org.junit.jupiter.api.Test;

public class CancelCompositeObservationResponseTest {

@Test
public void create_failure_reponse() {
CancelCompositeObservationResponse response = new CancelCompositeObservationResponse(ResponseCode.NOT_FOUND,
null, null, null, null, null);
assertEquals(response.getCode(), ResponseCode.NOT_FOUND);
assertNull(response.getContent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import static org.eclipse.leshan.core.ResponseCode.CONTENT;
import static org.eclipse.leshan.core.node.LwM2mSingleResource.newResource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.leshan.core.ResponseCode;
import org.eclipse.leshan.core.node.LwM2mNode;
import org.eclipse.leshan.core.node.LwM2mPath;
import org.junit.jupiter.api.Test;
Expand All @@ -42,4 +44,11 @@ public void should_create_response_with_content() {
// then
assertEquals(exampleContent, response.getContent());
}

@Test
public void create_failure_reponse() {
ObserveCompositeResponse response = ObserveCompositeResponse.notFound();
assertEquals(response.getCode(), ResponseCode.NOT_FOUND);
assertNull(response.getContent());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* Copyright (c) 2024 Sierra Wireless and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.html.
*
* Contributors:
* Sierra Wireless - initial API and implementation
*******************************************************************************/
package org.eclipse.leshan.core.response;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.eclipse.leshan.core.ResponseCode;
import org.junit.jupiter.api.Test;

public class ReadCompositeResponseTest {

@Test
public void create_failure_reponse() {
ReadCompositeResponse response = ReadCompositeResponse.notFound();
assertEquals(response.getCode(), ResponseCode.NOT_FOUND);
assertNull(response.getContent());
}
}