From 845224c8d59a573d47e9cbbb7d4c43516a5e841d Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Sun, 13 Mar 2011 21:39:44 +0000 Subject: [PATCH] Eliminate some warnings from IntelliJ inspections. There are still quite a few but they are all harmless. --- src/com/google/bitcoin/core/Base58.java | 4 ++-- src/com/google/bitcoin/core/NetworkConnection.java | 4 ++-- src/com/google/bitcoin/core/Peer.java | 6 +++--- src/com/google/bitcoin/core/Script.java | 5 +++-- src/com/google/bitcoin/core/Transaction.java | 1 + src/com/google/bitcoin/core/Utils.java | 11 +++++------ 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/com/google/bitcoin/core/Base58.java b/src/com/google/bitcoin/core/Base58.java index a2226a65..5f2fd3f3 100644 --- a/src/com/google/bitcoin/core/Base58.java +++ b/src/com/google/bitcoin/core/Base58.java @@ -48,8 +48,8 @@ public class Base58 { } s.insert(0, ALPHABET.charAt(bi.intValue())); // Convert leading zeros too. - for (int i = 0; i < input.length; i++) { - if (input[i] == 0) + for (byte anInput : input) { + if (anInput == 0) s.insert(0, ALPHABET.charAt(0)); else break; diff --git a/src/com/google/bitcoin/core/NetworkConnection.java b/src/com/google/bitcoin/core/NetworkConnection.java index 0813642f..97d2c16e 100644 --- a/src/com/google/bitcoin/core/NetworkConnection.java +++ b/src/com/google/bitcoin/core/NetworkConnection.java @@ -52,7 +52,7 @@ public class NetworkConnection { private final OutputStream out; private final InputStream in; // The IP address to which we are connecting. - private InetAddress remoteIp; + private final InetAddress remoteIp; private boolean usesChecksumming; private final NetworkParameters params; static final private boolean PROTOCOL_LOG = false; @@ -82,7 +82,7 @@ public class NetworkConnection { // And get one back ... readMessage(); // Switch to the new protocol version. - int peerVersion = (int) ver.clientVersion; + int peerVersion = ver.clientVersion; LOG("Connected to peer, version is " + peerVersion + ", services=" + Long.toHexString( ver.localServices) + ", time=" + new Date(ver.time.longValue() * 1000).toString()); // BitCoinJ is a client mode implementation. That means there's not much point in us talking to other client diff --git a/src/com/google/bitcoin/core/Peer.java b/src/com/google/bitcoin/core/Peer.java index bade7e2e..41fb2594 100644 --- a/src/com/google/bitcoin/core/Peer.java +++ b/src/com/google/bitcoin/core/Peer.java @@ -44,7 +44,7 @@ public class Peer { private CountDownLatch chainCompletionLatch; // When we want to download a block or transaction from a peer, the InventoryItem is put here whilst waiting for // the response. Synchronized on itself. - private List> pendingGetBlockFutures; + private final List> pendingGetBlockFutures; /** * Construct a peer that handles the given network connection and reads/writes from the given block chain. Note that @@ -217,8 +217,8 @@ public class Peer { // decide whether to wait forever, wait for a short while or check later after doing other work. private class GetDataFuture implements Future { private boolean cancelled; - private InventoryItem item; - private CountDownLatch latch; + private final InventoryItem item; + private final CountDownLatch latch; private T result; GetDataFuture(InventoryItem item) { diff --git a/src/com/google/bitcoin/core/Script.java b/src/com/google/bitcoin/core/Script.java index 308b046b..338bcc33 100644 --- a/src/com/google/bitcoin/core/Script.java +++ b/src/com/google/bitcoin/core/Script.java @@ -51,12 +51,12 @@ public class Script { private int cursor; // The stack consists of an ordered series of data buffers growing from zero up. - private Stack stack; + private final Stack stack; // The program is a set of byte[]s where each element is either [opcode] or [data, data, data ...] private List chunks; private boolean tracing; byte[] programCopy; // TODO: remove this - private NetworkParameters params; + private final NetworkParameters params; /** Concatenates two scripts to form a new one. This is used when verifying transactions. */ public static Script join(Script a, Script b) throws ScriptException { @@ -321,6 +321,7 @@ public class Script { pushBool(true); } + @SuppressWarnings({"SameParameterValue"}) private void pushBool(boolean val) { stack.push(new byte[] { val ? (byte)1 : (byte)0 }); } diff --git a/src/com/google/bitcoin/core/Transaction.java b/src/com/google/bitcoin/core/Transaction.java index 2394439d..65bb678b 100644 --- a/src/com/google/bitcoin/core/Transaction.java +++ b/src/com/google/bitcoin/core/Transaction.java @@ -254,6 +254,7 @@ public class Transaction extends Message implements Serializable { * @param hashType This should always be set to SigHash.ALL currently. Other types are unused. * @param wallet A wallet is required to fetch the keys needed for signing. */ + @SuppressWarnings({"SameParameterValue"}) public void signInputs(SigHash hashType, Wallet wallet) throws ScriptException { assert inputs.size() > 0; assert outputs.size() > 0; diff --git a/src/com/google/bitcoin/core/Utils.java b/src/com/google/bitcoin/core/Utils.java index eb90888c..9e0785fd 100644 --- a/src/com/google/bitcoin/core/Utils.java +++ b/src/com/google/bitcoin/core/Utils.java @@ -28,13 +28,14 @@ import java.security.NoSuchAlgorithmException; * A collection of various utility methods that are helpful for working with the BitCoin protocol. * To enable debug logging from the library, run with -Dbitcoinj.logging=true on your command line. */ +@SuppressWarnings({"SameParameterValue"}) public class Utils { /** How many nanocoins there are in a BitCoin. */ public static final BigInteger COIN = new BigInteger("100000000", 10); /** How many nanocoins there are in 0.01 BitCoins. */ public static final BigInteger CENT = new BigInteger("1000000", 10); - private static boolean logging; + private static final boolean logging; static { logging = Boolean.parseBoolean(System.getProperty("bitcoinj.logging", "false")); @@ -98,8 +99,7 @@ public class Utils { MessageDigest digest = MessageDigest.getInstance("SHA-256"); digest.update(input, offset, length); byte[] first = digest.digest(); - byte[] second = digest.digest(first); - return second; + return digest.digest(first); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); // Cannot happen. } @@ -115,8 +115,7 @@ public class Utils { digest.update(input1, offset1, length1); digest.update(input2, offset2, length2); byte[] first = digest.digest(); - byte[] second = digest.digest(first); - return second; + return digest.digest(first); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); // Cannot happen. } @@ -154,7 +153,7 @@ public class Utils { return ((bytes[offset++] & 0xFFL) << 0) | ((bytes[offset++] & 0xFFL) << 8) | ((bytes[offset++] & 0xFFL) << 16) | - ((bytes[offset++] & 0xFFL) << 24); + ((bytes[offset] & 0xFFL) << 24); } public static long readUint32BE(byte[] bytes, int offset) {