Fixed NullPointerException
This commit is contained in:
parent
956ed61b14
commit
239c6ec7f4
@ -96,7 +96,7 @@ public class ObjectMessage implements MessagePayload {
|
||||
}
|
||||
|
||||
public InventoryVector getInventoryVector() {
|
||||
return new InventoryVector(
|
||||
return InventoryVector.fromHash(
|
||||
Bytes.truncate(cryptography().doubleSha512(nonce, getPayloadBytesWithoutNonce()), 32)
|
||||
);
|
||||
}
|
||||
|
@ -52,10 +52,19 @@ public class InventoryVector implements Streamable, Serializable {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public InventoryVector(byte[] hash) {
|
||||
private InventoryVector(byte[] hash) {
|
||||
if (hash == null) throw new IllegalArgumentException("hash must not be null");
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
public static InventoryVector fromHash(byte[] hash) {
|
||||
if (hash == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new InventoryVector(hash);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(OutputStream out) throws IOException {
|
||||
out.write(hash);
|
||||
|
@ -184,7 +184,7 @@ public class Message implements ExtendedEncoding.ExtendedType {
|
||||
MPArray<MPBinary> parents = (MPArray<MPBinary>) map.get(mp("parents"));
|
||||
if (parents != null) {
|
||||
for (MPBinary parent : parents) {
|
||||
builder.addParent(new InventoryVector(parent.getValue()));
|
||||
builder.addParent(InventoryVector.fromHash(parent.getValue()));
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -105,7 +105,7 @@ public class Vote implements ExtendedEncoding.ExtendedType {
|
||||
Vote.Builder builder = new Vote.Builder();
|
||||
MPType<?> msgId = map.get(mp("msgId"));
|
||||
if (msgId instanceof MPBinary) {
|
||||
builder.msgId(new InventoryVector(((MPBinary) msgId).getValue()));
|
||||
builder.msgId(InventoryVector.fromHash(((MPBinary) msgId).getValue()));
|
||||
}
|
||||
builder.vote(str(map.get(mp("vote"))));
|
||||
return new Vote(builder);
|
||||
|
@ -103,8 +103,10 @@ class V3MessageFactory {
|
||||
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
|
||||
payload = Factory.getObjectPayload(objectType, version, stream, dataStream, data.length);
|
||||
} catch (Exception e) {
|
||||
LOG.trace("Could not parse object payload - using generic payload instead", e);
|
||||
LOG.info(Strings.hex(data).toString());
|
||||
if (LOG.isTraceEnabled()) {
|
||||
LOG.trace("Could not parse object payload - using generic payload instead", e);
|
||||
LOG.trace(Strings.hex(data).toString());
|
||||
}
|
||||
payload = new GenericPayload(version, stream, data);
|
||||
}
|
||||
|
||||
@ -165,7 +167,7 @@ class V3MessageFactory {
|
||||
}
|
||||
|
||||
private static InventoryVector parseInventoryVector(InputStream stream) throws IOException {
|
||||
return new InventoryVector(Decode.bytes(stream, 32));
|
||||
return InventoryVector.fromHash(Decode.bytes(stream, 32));
|
||||
}
|
||||
|
||||
private static NetworkAddress parseAddress(InputStream stream, boolean light) throws IOException {
|
||||
|
@ -72,7 +72,7 @@ public class BitmessageContextTest {
|
||||
|
||||
@Override
|
||||
public Item getItem(byte[] initialHash) {
|
||||
return items.get(new InventoryVector(initialHash));
|
||||
return items.get(InventoryVector.fromHash(initialHash));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -86,12 +86,12 @@ public class BitmessageContextTest {
|
||||
|
||||
@Override
|
||||
public void putObject(Item item) {
|
||||
items.put(new InventoryVector(cryptography().getInitialHash(item.object)), item);
|
||||
items.put(InventoryVector.fromHash(cryptography().getInitialHash(item.object)), item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putObject(ObjectMessage object, long nonceTrialsPerByte, long extraBytes) {
|
||||
items.put(new InventoryVector(cryptography().getInitialHash(object)), new Item(object, nonceTrialsPerByte, extraBytes));
|
||||
items.put(InventoryVector.fromHash(cryptography().getInitialHash(object)), new Item(object, nonceTrialsPerByte, extraBytes));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,7 +66,7 @@ public class TestUtils {
|
||||
public static InventoryVector randomInventoryVector() {
|
||||
byte[] bytes = new byte[32];
|
||||
RANDOM.nextBytes(bytes);
|
||||
return new InventoryVector(bytes);
|
||||
return InventoryVector.fromHash(bytes);
|
||||
}
|
||||
|
||||
public static InputStream getResource(String resourceName) {
|
||||
|
@ -69,7 +69,7 @@ public class JdbcInventory extends JdbcHelper implements Inventory {
|
||||
"WHERE expires > " + now(-5 * MINUTE) + " AND stream = " + stream)
|
||||
) {
|
||||
while (rs.next()) {
|
||||
result.put(new InventoryVector(rs.getBytes("hash")), rs.getLong("expires"));
|
||||
result.put(InventoryVector.fromHash(rs.getBytes("hash")), rs.getLong("expires"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
|
@ -110,7 +110,7 @@ public class JdbcMessageRepository extends AbstractMessageRepository implements
|
||||
Plaintext.Builder builder = Plaintext.readWithoutSignature(type, data);
|
||||
long id = rs.getLong("id");
|
||||
builder.id(id);
|
||||
builder.IV(new InventoryVector(iv));
|
||||
builder.IV(InventoryVector.fromHash(iv));
|
||||
builder.from(ctx.getAddressRepository().getAddress(rs.getString("sender")));
|
||||
builder.to(ctx.getAddressRepository().getAddress(rs.getString("recipient")));
|
||||
builder.ackData(rs.getBytes("ack_data"));
|
||||
|
Loading…
Reference in New Issue
Block a user