Skip to content

Commit 3287745

Browse files
committed
Findbugs fixes.
1 parent f812fe2 commit 3287745

File tree

5 files changed

+63
-34
lines changed

5 files changed

+63
-34
lines changed

src/main/java/com/ning/http/client/AsyncHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public Request build() {
275275
if (i >= 0) {
276276
url = url.substring(0, i);
277277
}
278-
signatureCalculator.calculateAndAddSignature(baseURL, request, this);
278+
signatureCalculator.calculateAndAddSignature(url, request, this);
279279
}
280280
return super.build();
281281
}

src/main/java/com/ning/http/client/ntlm/NTLMEngine.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class NTLMEngine {
7676
java.security.SecureRandom rnd = null;
7777
try {
7878
rnd = java.security.SecureRandom.getInstance("SHA1PRNG");
79-
} catch (Exception e) {
79+
} catch (Exception ignored) {
8080
}
8181
RND_GEN = rnd;
8282
}
@@ -753,7 +753,7 @@ String getResponse() throws UnsupportedEncodingException {
753753
} else {
754754
resp = messageContents;
755755
}
756-
return new String(Base64.encode(resp));
756+
return Base64.encode(resp);
757757
}
758758

759759
}
@@ -996,8 +996,7 @@ String getResponse() throws UnsupportedEncodingException {
996996
int domainOffset = ntRespOffset + ntRespLen;
997997
int userOffset = domainOffset + domainLen;
998998
int hostOffset = userOffset + userLen;
999-
int sessionKeyOffset = hostOffset + hostLen;
1000-
int finalLength = sessionKeyOffset + 0;
999+
int finalLength = hostOffset + hostLen;
10011000

10021001
// Start the response. Length includes signature and type
10031002
prepareResponse(finalLength, 3);
@@ -1127,7 +1126,6 @@ void update(byte[] input) {
11271126
int transferAmt = input.length - inputIndex;
11281127
System.arraycopy(input, inputIndex, dataBuffer, curBufferPos, transferAmt);
11291128
count += transferAmt;
1130-
curBufferPos += transferAmt;
11311129
}
11321130
}
11331131

src/main/java/com/ning/http/client/oauth/OAuthSignatureCalculator.java

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ public class OAuthSignatureCalculator
4545
implements SignatureCalculator {
4646
public final static String HEADER_AUTHORIZATION = "Authorization";
4747

48-
private final String KEY_OAUTH_CONSUMER_KEY = "oauth_consumer_key";
49-
private final String KEY_OAUTH_NONCE = "oauth_nonce";
50-
private final String KEY_OAUTH_SIGNATURE = "oauth_signature";
51-
private final String KEY_OAUTH_SIGNATURE_METHOD = "oauth_signature_method";
52-
private final String KEY_OAUTH_TIMESTAMP = "oauth_timestamp";
53-
private final String KEY_OAUTH_TOKEN = "oauth_token";
54-
private final String KEY_OAUTH_VERSION = "oauth_version";
48+
private static final String KEY_OAUTH_CONSUMER_KEY = "oauth_consumer_key";
49+
private static final String KEY_OAUTH_NONCE = "oauth_nonce";
50+
private static final String KEY_OAUTH_SIGNATURE = "oauth_signature";
51+
private static final String KEY_OAUTH_SIGNATURE_METHOD = "oauth_signature_method";
52+
private static final String KEY_OAUTH_TIMESTAMP = "oauth_timestamp";
53+
private static final String KEY_OAUTH_TOKEN = "oauth_token";
54+
private static final String KEY_OAUTH_VERSION = "oauth_version";
5555

56-
private final String OAUTH_VERSION_1_0 = "1.0";
57-
private final String OAUTH_SIGNATURE_METHOD = "HMAC-SHA1";
56+
private static final String OAUTH_VERSION_1_0 = "1.0";
57+
private static final String OAUTH_SIGNATURE_METHOD = "HMAC-SHA1";
5858

5959
/**
6060
* To generate Nonce, need some (pseudo)randomness; no need for
@@ -84,12 +84,12 @@ public OAuthSignatureCalculator(ConsumerKey consumerAuth, RequestToken userAuth)
8484
//@Override // silly 1.5; doesn't allow this for interfaces
8585

8686
public void calculateAndAddSignature(String baseURL, Request request, RequestBuilderBase<?> requestBuilder) {
87-
String method = request.getMethod().toString(); // POST etc
87+
String method = request.getMethod(); // POST etc
8888
String nonce = generateNonce();
8989
long timestamp = System.currentTimeMillis() / 1000L;
9090
String signature = calculateSignature(method, baseURL, timestamp, nonce, request.getParams(), request.getQueryParams());
9191
String headerValue = constructAuthHeader(signature, nonce, timestamp);
92-
requestBuilder = requestBuilder.setHeader(HEADER_AUTHORIZATION, headerValue);
92+
requestBuilder.setHeader(HEADER_AUTHORIZATION, headerValue);
9393
}
9494

9595
/**
@@ -260,5 +260,25 @@ public int compareTo(Parameter other) {
260260
public String toString() {
261261
return key + "=" + value;
262262
}
263+
264+
@Override
265+
public boolean equals(Object o) {
266+
if (this == o) return true;
267+
if (o == null || getClass() != o.getClass()) return false;
268+
269+
Parameter parameter = (Parameter) o;
270+
271+
if (!key.equals(parameter.key)) return false;
272+
if (!value.equals(parameter.value)) return false;
273+
274+
return true;
275+
}
276+
277+
@Override
278+
public int hashCode() {
279+
int result = key.hashCode();
280+
result = 31 * result + value.hashCode();
281+
return result;
282+
}
263283
}
264284
}

src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,22 +1904,29 @@ public boolean doHandle(final FilterChainContext ctx,
19041904
AtomicInteger written = new AtomicInteger();
19051905
boolean last = false;
19061906
requestPacket.setContentLengthLong(f.length());
1907-
for (byte[] buf = new byte[MAX_CHUNK_SIZE]; !last; ) {
1908-
Buffer b = null;
1909-
int read;
1910-
if ((read = fis.read(buf)) < 0) {
1911-
last = true;
1912-
b = Buffers.EMPTY_BUFFER;
1907+
try {
1908+
for (byte[] buf = new byte[MAX_CHUNK_SIZE]; !last; ) {
1909+
Buffer b = null;
1910+
int read;
1911+
if ((read = fis.read(buf)) < 0) {
1912+
last = true;
1913+
b = Buffers.EMPTY_BUFFER;
1914+
}
1915+
if (b != Buffers.EMPTY_BUFFER) {
1916+
written.addAndGet(read);
1917+
b = Buffers.wrap(mm, buf, 0, read);
1918+
}
1919+
1920+
final HttpContent content =
1921+
requestPacket.httpContentBuilder().content(b).
1922+
last(last).build();
1923+
ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null));
19131924
}
1914-
if (b != Buffers.EMPTY_BUFFER) {
1915-
written.addAndGet(read);
1916-
b = Buffers.wrap(mm, buf, 0, read);
1925+
} finally {
1926+
try {
1927+
fis.close();
1928+
} catch (IOException ignored) {
19171929
}
1918-
1919-
final HttpContent content =
1920-
requestPacket.httpContentBuilder().content(b).
1921-
last(last).build();
1922-
ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null));
19231930
}
19241931

19251932
return true;

src/main/java/com/ning/http/client/resumable/PropertiesBasedResumableProcessor.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ public void save(Map<String, Long> map) {
6060
FileOutputStream os = null;
6161
try {
6262

63-
TMP.mkdirs();
63+
if (!TMP.mkdirs()) {
64+
throw new IllegalStateException("Unable to create directory: " + TMP.getAbsolutePath());
65+
}
6466
File f = new File(TMP, storeName);
65-
f.createNewFile();
67+
if (!f.createNewFile()) {
68+
throw new IllegalStateException("Unable to create temp file: " + f.getAbsolutePath());
69+
}
6670
if (!f.canWrite()) {
6771
throw new IllegalStateException();
6872
}
@@ -79,7 +83,7 @@ public void save(Map<String, Long> map) {
7983
if (os != null) {
8084
try {
8185
os.close();
82-
} catch (IOException e) {
86+
} catch (IOException ignored) {
8387
}
8488
}
8589
}

0 commit comments

Comments
 (0)