Skip to content

Commit

Permalink
More safety in UnsignedXrayClient (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anuraag Agrawal authored May 26, 2020
1 parent 3fcb0a1 commit 450a4bb
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import javax.annotation.Nullable;

/**
* A simple client for sending API requests via the X-Ray daemon. Requests do not have to be
Expand All @@ -35,7 +36,8 @@ public class UnsignedXrayClient {
// Visible for testing
static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
.setSerializationInclusion(Include.NON_EMPTY)
.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE)
// Use deprecated field to support older Jackson versions for now.
.setPropertyNamingStrategy(PropertyNamingStrategy.PASCAL_CASE_TO_CAMEL_CASE)
.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
Expand Down Expand Up @@ -140,7 +142,12 @@ private static String readResponseString(HttpURLConnection connection) {
}
}

private static void readTo(InputStream is, ByteArrayOutputStream os) throws IOException {
private static void readTo(@Nullable InputStream is, ByteArrayOutputStream os) throws IOException {
// It is possible for getErrorStream to return null, though since we don't read it for success cases in practice it
// shouldn't happen. Check just in case.
if (is == null) {
return;
}
int b;
while ((b = is.read()) != -1) {
os.write(b);
Expand Down

0 comments on commit 450a4bb

Please sign in to comment.