Skip to content

Commit

Permalink
Dealt with several compiler notices by verifying and then fixing or s…
Browse files Browse the repository at this point in the history
…uppressing. Reduces compilation output noise.
  • Loading branch information
Piotr Włodarek authored and mikehearn committed May 25, 2014
1 parent cc6090a commit c08c68f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
12 changes: 10 additions & 2 deletions core/src/main/java/com/google/bitcoin/core/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,9 @@ public ListenableFuture<List<Transaction>> downloadDependencies(Transaction tx)
log.info("{}: Downloading dependencies of {}", getAddress(), tx.getHashAsString());
final LinkedList<Transaction> results = new LinkedList<Transaction>();
// future will be invoked when the entire dependency tree has been walked and the results compiled.
final ListenableFuture future = downloadDependenciesInternal(tx, new Object(), results);
final ListenableFuture<Object> future = downloadDependenciesInternal(tx, new Object(), results);
final SettableFuture<List<Transaction>> resultFuture = SettableFuture.create();
Futures.addCallback(future, new FutureCallback() {
Futures.addCallback(future, new FutureCallback<Object>() {
public void onSuccess(Object ignored) {
resultFuture.set(results);
}
Expand Down Expand Up @@ -1083,6 +1083,10 @@ private void processInv(InventoryMessage inv) {
* If you want the block right away and don't mind waiting for it, just call .get() on the result. Your thread
* will block until the peer answers.
*/
@SuppressWarnings("unchecked")
// The 'unchecked conversion' warning being suppressed here comes from the sendSingleGetData() formally returning
// ListenableFuture instead of ListenableFuture<Block>. This is okay as sendSingleGetData() actually returns
// ListenableFuture<Block> in this context. Note that sendSingleGetData() is also used for Transactions.
public ListenableFuture<Block> getBlock(Sha256Hash blockHash) {
// This does not need to be locked.
log.info("Request to fetch block {}", blockHash);
Expand All @@ -1096,6 +1100,10 @@ public ListenableFuture<Block> getBlock(Sha256Hash blockHash) {
* retrieved this way because peers don't have a transaction ID to transaction-pos-on-disk index, and besides,
* in future many peers will delete old transaction data they don't need.
*/
@SuppressWarnings("unchecked")
// The 'unchecked conversion' warning being suppressed here comes from the sendSingleGetData() formally returning
// ListenableFuture instead of ListenableFuture<Transaction>. This is okay as sendSingleGetData() actually returns
// ListenableFuture<Transaction> in this context. Note that sendSingleGetData() is also used for Blocks.
public ListenableFuture<Transaction> getPeerMempoolTransaction(Sha256Hash hash) {
// This does not need to be locked.
// TODO: Unit test this method.
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/com/google/bitcoin/net/ProtobufParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ protected void timeoutOccurred() {

// Deserializes and provides a listener event (buff must not have the length prefix in it)
// Does set the buffers's position to its limit
@SuppressWarnings("unchecked")
// The warning 'unchecked cast' being suppressed here comes from the build() formally returning
// a MessageLite-derived class that cannot be statically guaranteed to be the MessageType.
private void deserializeMessage(ByteBuffer buff) throws Exception {
MessageType msg = (MessageType) prototype.newBuilderForType().mergeFrom(ByteString.copyFrom(buff)).build();
resetTimeout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ public abstract class ServerConnectionEventHandler {
* {@link StoredPaymentChannelServerStates#getChannel(com.google.bitcoin.core.Sha256Hash)} with the id provided in
* {@link ServerConnectionEventHandler#channelOpen(com.google.bitcoin.core.Sha256Hash)}</p>
*/
@SuppressWarnings("unchecked")
// The warning 'unchecked call to write(MessageType)' being suppressed here comes from the build()
// formally returning MessageLite-derived class that cannot be statically guaranteed to be the same MessageType
// that is used in connectionChannel.
protected final synchronized void closeChannel() {
if (connectionChannel == null)
throw new IllegalStateException("Channel is not fully initialized/has already been closed");

connectionChannel.write(Protos.TwoWayChannelMessage.newBuilder()
.setType(Protos.TwoWayChannelMessage.MessageType.CLOSE)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ public void addUnspentTransactionOutput(StoredTransactionOutput out) throws Bloc
// Calculate the toAddress (if any)
String dbAddress = "";
int type = 0;
Script outputScript = null;
Script outputScript = null;
try
{
outputScript = new Script(out.getScriptBytes());
Expand Down
4 changes: 4 additions & 0 deletions core/src/test/java/com/google/bitcoin/core/WalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ private void receiveATransaction(Wallet wallet, Address toAddress) throws Except
assertTrue(depthFuture.isDone());
}

@SuppressWarnings("deprecation")
// Having a test for deprecated method getFromAddress() is no evil so we suppress the warning here.
private void basicSanityChecks(Wallet wallet, Transaction t, Address fromAddress, Address destination) throws VerificationException {
assertEquals("Wrong number of tx inputs", 1, t.getInputs().size());
assertEquals(fromAddress, t.getInputs().get(0).getScriptSig().getFromAddress(params));
Expand Down Expand Up @@ -389,6 +391,8 @@ private void spendUnconfirmedChange(Wallet wallet, Transaction t2, KeyParameter
}

@Test
@SuppressWarnings("deprecation")
// Having a test for deprecated method getFromAddress() is no evil so we suppress the warning here.
public void customTransactionSpending() throws Exception {
// We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change.
BigInteger v1 = Utils.toNanoCoins(3, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void main(String[] args) throws Exception {
for (final InetAddress addr : addrs) {
InetSocketAddress address = new InetSocketAddress(addr, params.getPort());
final Peer peer = new Peer(params, new VersionMessage(params, 0), null, new PeerAddress(address));
final SettableFuture future = SettableFuture.create();
final SettableFuture<Void> future = SettableFuture.create();
// Once the connection has completed version handshaking ...
peer.addEventListener(new AbstractPeerEventListener() {
public void onPeerConnected(Peer p, int peerCount) {
Expand Down

0 comments on commit c08c68f

Please sign in to comment.