Skip to content

Commit e3f8f3a

Browse files
committed
Fix #634: NPE when default file persistence tries to restore persisted data using only header data array.
Signed-off-by: Matt Magoffin <matt@solarnetwork.net>
1 parent f30e10b commit e3f8f3a

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/** Copyright (c) 2014 IBM Corp.
2+
*
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* and Eclipse Distribution License v1.0 which accompany this distribution.
6+
*
7+
* The Eclipse Public License is available at
8+
* http://www.eclipse.org/legal/epl-v10.html
9+
* and the Eclipse Distribution License is available at
10+
* http://www.eclipse.org/org/documents/edl-v10.php.
11+
*
12+
*******************************************************************************/
13+
14+
package org.eclipse.paho.client.mqttv3.test.internal;
15+
16+
import java.util.logging.Logger;
17+
18+
import org.eclipse.paho.client.mqttv3.internal.MqttPersistentData;
19+
import org.eclipse.paho.client.mqttv3.test.logging.LoggingUtilities;
20+
import org.eclipse.paho.client.mqttv3.test.utilities.Utility;
21+
import org.junit.AfterClass;
22+
import org.junit.Assert;
23+
import org.junit.BeforeClass;
24+
import org.junit.Test;
25+
26+
/**
27+
* Tests mqtt topic wildcards
28+
*/
29+
public class MqttPersistentDataTest {
30+
31+
static final Class<?> cclass = MqttPersistentDataTest.class;
32+
private static final String className = cclass.getName();
33+
private static final Logger log = Logger.getLogger(className);
34+
35+
@BeforeClass
36+
public static void setUpBeforeClass() throws Exception {
37+
String methodName = Utility.getMethodName();
38+
LoggingUtilities.banner(log, cclass, methodName);
39+
}
40+
41+
@AfterClass
42+
public static void tearDownAfterClass() throws Exception {
43+
String methodName = Utility.getMethodName();
44+
LoggingUtilities.banner(log, cclass, methodName);
45+
}
46+
47+
@Test
48+
public void testConstructWithNullPayload() throws Exception {
49+
byte[] head = new byte[] {1,2,3};
50+
MqttPersistentData data = new MqttPersistentData("foo", head, 0, head.length, null, 0, 0);
51+
Assert.assertArrayEquals("Header data", head, data.getHeaderBytes());
52+
Assert.assertNotSame("Header cloned", head, data.getHeaderBytes());
53+
}
54+
55+
}

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/MqttPersistentData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public MqttPersistentData( String key,
6060
this.header = header.clone();
6161
this.hOffset = hOffset;
6262
this.hLength = hLength;
63-
this.payload = payload.clone();
63+
this.payload = (payload != null ? payload.clone() : null);
6464
this.pOffset = pOffset;
6565
this.pLength = pLength;
6666
}

0 commit comments

Comments
 (0)