Skip to content

Commit

Permalink
Fix nullpointer
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed Sep 27, 2018
1 parent 8eabd66 commit dbe0993
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/src/main/java/bisq/core/dao/state/blockchain/BaseBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@

import io.bisq.generated.protobuffer.PB;

import java.util.Optional;

import lombok.Data;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/**
Expand All @@ -33,6 +36,7 @@ public abstract class BaseBlock {
protected final int height;
protected final long time; // in ms
protected final String hash;
@Nullable // in case of first block in the blockchain
protected final String previousBlockHash;

BaseBlock(int height, long time, String hash, String previousBlockHash) {
Expand All @@ -48,11 +52,13 @@ public abstract class BaseBlock {
///////////////////////////////////////////////////////////////////////////////////////////

PB.BaseBlock.Builder getBaseBlockBuilder() {
return PB.BaseBlock.newBuilder()
PB.BaseBlock.Builder builder = PB.BaseBlock.newBuilder()
.setHeight(height)
.setTime(time)
.setHash(hash)
.setPreviousBlockHash(previousBlockHash);
.setHash(hash);
Optional.ofNullable(previousBlockHash).ifPresent(builder::setPreviousBlockHash);
return builder;

}

@Override
Expand Down

0 comments on commit dbe0993

Please sign in to comment.