From 84681e1eb418a288174428d0e16a383f1ed496b3 Mon Sep 17 00:00:00 2001 From: andrew-coleman Date: Fri, 20 Sep 2019 15:30:47 +0100 Subject: [PATCH] FGJ-38 Throw exception if no discovery peers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If discovery is set to true but the the channel definition in the networkconfig doesn’t contain any peers with the ‘discover’ role, then a NPE is thrown. It now throws a checked ServiceDiscoveryException Change-Id: I43da4804119dd12df364e975af303e9f617dc355 Signed-off-by: andrew-coleman --- src/main/java/org/hyperledger/fabric/sdk/Channel.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/hyperledger/fabric/sdk/Channel.java b/src/main/java/org/hyperledger/fabric/sdk/Channel.java index b368080a..2e0f7cb0 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/Channel.java +++ b/src/main/java/org/hyperledger/fabric/sdk/Channel.java @@ -166,7 +166,6 @@ public class Channel implements Serializable { private static final String CHAINCODE_EVENTS_TAG = "CHAINCODE_EVENTS_HANDLE"; final Collection orderers = Collections.synchronizedCollection(new LinkedList<>()); private transient Map ordererEndpointMap = Collections.synchronizedMap(new HashMap<>()); - // Name of the channel is only meaningful to the client private final String name; private transient String toString; @@ -384,7 +383,6 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE for (Orderer orderer : orderers) { ordererEndpointMap.put(orderer.getEndpoint(), orderer); } - } /** @@ -4387,6 +4385,9 @@ public Collection sendTransactionProposalToEndorsers(Transacti if (transactionProposalRequest.getChaincodeID() == null) { throw new InvalidArgumentException("The proposalRequest's chaincode ID is null"); } + if (null == serviceDiscovery) { + throw new ServiceDiscoveryException("The channel is not configured with any peers with the 'discover' role"); + } logger.debug(format("Channel %s sendTransactionProposalToEndorsers chaincode name: %s", name, chaincodeName)); TransactionContext transactionContext = getTransactionContext(transactionProposalRequest.getUserContext());