Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edge-case where Texture#toString has a NullPointer because gson s… #838

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -371,7 +370,7 @@ public enum TextureType {
* The model used for a profile texture.
*/
public enum TextureModel {
NORMAL,
WIDE,
SLIM;
}

Expand All @@ -390,7 +389,7 @@ public static class Texture {
*/
public Texture(String url, Map<String, String> metadata) {
this.url = url;
this.metadata = new HashMap<>(metadata);
this.metadata = metadata;
onebeastchris marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -408,6 +407,10 @@ public String getURL() {
* @return The metadata value corresponding to the given key.
*/
public String getMetadata(String key) {
if (this.metadata == null) {
return null;
}

return this.metadata.get(key);
}

Expand All @@ -418,7 +421,7 @@ public String getMetadata(String key) {
*/
public TextureModel getModel() {
String model = this.getMetadata("model");
return model != null && model.equals("slim") ? TextureModel.SLIM : TextureModel.NORMAL;
return model != null && model.equals("slim") ? TextureModel.SLIM : TextureModel.WIDE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public static <T> T makeRequest(@Nullable ProxyInfo proxy, URI uri, Object input
throw new IllegalArgumentException("URI cannot be null.");
}

HttpResponse response = createHttpClient(proxy).execute(input == null ? new HttpRequest("GET", uri.toURL()) :
new HttpContentRequest("POST", uri.toURL()).setContent(HttpContent.string(GSON.toJson(input))));
HttpResponse response = createHttpClient(proxy)
.execute(input == null ? new HttpRequest("GET", uri.toURL()) :
new HttpContentRequest("POST", uri.toURL())
.setContent(HttpContent.string(GSON.toJson(input)))
.setHeader(Headers.CONTENT_TYPE, ContentTypes.APPLICATION_JSON.toString()));

if (responseType == null) {
return null;
Expand Down
Loading