Skip to content

Commit 043e40a

Browse files
author
Christoph Büscher
authored
Fix unreachable error condition in AmazonS3Fixture (#32005)
The `else` branch where currently the error response should be thrown is not reachable because `handler` is always non-null inside the previous outer check. Moving error creation into an else branch on the other condition check, removing the other superflous check for non-null handler inside the first branch.
1 parent 0b7e7be commit 043e40a

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

plugins/repository-s3/src/test/java/org/elasticsearch/repositories/s3/AmazonS3Fixture.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
*/
1919
package org.elasticsearch.repositories.s3;
2020

21-
import org.elasticsearch.test.fixture.AbstractHttpFixture;
2221
import com.amazonaws.util.DateUtils;
22+
2323
import org.elasticsearch.common.Strings;
2424
import org.elasticsearch.common.io.Streams;
2525
import org.elasticsearch.common.path.PathTrie;
2626
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
2727
import org.elasticsearch.rest.RestStatus;
2828
import org.elasticsearch.rest.RestUtils;
29+
import org.elasticsearch.test.fixture.AbstractHttpFixture;
2930

3031
import java.io.BufferedInputStream;
3132
import java.io.ByteArrayInputStream;
@@ -93,23 +94,21 @@ protected Response handle(final Request request) throws IOException {
9394
return newError(request.getId(), RestStatus.FORBIDDEN, "AccessDenied", "Bad access key", "");
9495
}
9596

96-
if (handler != null) {
97-
final String bucket = request.getParam("bucket");
98-
if (bucket != null && permittedBucket.equals(bucket) == false) {
99-
// allow a null bucket to support the multi-object-delete API which
100-
// passes the bucket name in the host header instead of the URL.
101-
if (buckets.containsKey(bucket)) {
102-
return newError(request.getId(), RestStatus.FORBIDDEN, "AccessDenied", "Bad bucket", "");
103-
} else {
104-
return newBucketNotFoundError(request.getId(), bucket);
105-
}
97+
final String bucket = request.getParam("bucket");
98+
if (bucket != null && permittedBucket.equals(bucket) == false) {
99+
// allow a null bucket to support the multi-object-delete API which
100+
// passes the bucket name in the host header instead of the URL.
101+
if (buckets.containsKey(bucket)) {
102+
return newError(request.getId(), RestStatus.FORBIDDEN, "AccessDenied", "Bad bucket", "");
103+
} else {
104+
return newBucketNotFoundError(request.getId(), bucket);
106105
}
107-
return handler.handle(request);
108-
} else {
109-
return newInternalError(request.getId(), "No handler defined for request [" + request + "]");
110106
}
107+
return handler.handle(request);
108+
109+
} else {
110+
return newInternalError(request.getId(), "No handler defined for request [" + request + "]");
111111
}
112-
return null;
113112
}
114113

115114
public static void main(final String[] args) throws Exception {

0 commit comments

Comments
 (0)