Skip to content

Commit

Permalink
Merge pull request #1116 from amvanbaren/java-null-pointers
Browse files Browse the repository at this point in the history
Fix a "NullPointerException" could be thrown;
  • Loading branch information
amvanbaren authored Feb 14, 2025
2 parents 53ad2d7 + e9ea04b commit 6751ab2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ public ExtensionJson getExtension(String namespace, String extension, String tar

try {
var json = restTemplate.getForObject(urlTemplate, ExtensionJson.class, uriVariables);
makeDownloadsCompatible(json);
return proxy != null ? proxy.rewriteUrls(json) : json;
if(json != null) {
makeDownloadsCompatible(json);
if(proxy != null) {
proxy.rewriteUrls(json);
}
}

return json;
} catch (RestClientException exc) {
if(!isNotFound(exc)) {
var url = UriComponentsBuilder.fromUriString(urlTemplate).build(uriVariables);
Expand All @@ -144,8 +150,14 @@ public ExtensionJson getExtension(String namespace, String extension, String tar

try {
var json = restTemplate.getForObject(urlTemplate, ExtensionJson.class, uriVariables);
makeDownloadsCompatible(json);
return proxy != null ? proxy.rewriteUrls(json) : json;
if(json != null) {
makeDownloadsCompatible(json);
if(proxy != null) {
proxy.rewriteUrls(json);
}
}

return json;
} catch (RestClientException exc) {
if(!isNotFound(exc)) {
var url = UriComponentsBuilder.fromUriString(urlTemplate).build(uriVariables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,22 @@ public String download(String namespace, String extension, String version, Strin
throw propagateRestException(exc, method, urlTemplate, uriVariables);
}

URI location = null;
var statusCode = response.getStatusCode();
if(statusCode.is3xxRedirection()) {
var location = response.getHeaders().getLocation();
if(proxy != null) {
location = proxy.rewriteUrl(location);
}

return location.toString();
location = response.getHeaders().getLocation();
}
if(statusCode.isError() && statusCode != HttpStatus.NOT_FOUND) {
handleResponseError(urlTemplate, uriVariables, response);
}
if(location == null) {
throw new NotFoundException();
}

throw new NotFoundException();
if(proxy != null) {
location = proxy.rewriteUrl(location);
}
return location.toString();
}

@Override
Expand All @@ -207,20 +209,22 @@ public String getItemUrl(String namespace, String extension) {
throw propagateRestException(exc, method, urlTemplate, uriVariables);
}

URI location = null;
var statusCode = response.getStatusCode();
if(statusCode.is3xxRedirection()) {
var location = response.getHeaders().getLocation();
if(proxy != null) {
location = proxy.rewriteUrl(location);
}

return location.toString();
location = response.getHeaders().getLocation();
}
if(statusCode.isError() && statusCode != HttpStatus.NOT_FOUND) {
handleResponseError(urlTemplate, uriVariables, response);
}
if(location == null) {
throw new NotFoundException();
}

throw new NotFoundException();
if(proxy != null) {
location = proxy.rewriteUrl(location);
}
return location.toString();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ private ExtensionQueryResult.Extension getUpstreamExtension(Extension extension)
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(HttpHeaders.ACCEPT, "application/json;api-version=" + API_VERSION);
var result = vsCodeIdRestTemplate.postForObject(requestUrl, new HttpEntity<>(requestData, headers), ExtensionQueryResult.class);

if (result.results() != null && result.results().size() > 0) {
if (result != null && result.results() != null && !result.results().isEmpty()) {
var item = result.results().get(0);
if (item.extensions() != null && item.extensions().size() > 0) {
if (item.extensions() != null && !item.extensions().isEmpty()) {
return item.extensions().get(0);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ public EclipseProfile getUserProfile(String accessToken) {

private EclipseProfile parseEclipseProfile(ResponseEntity<String> response) {
var json = response.getBody();
if(json == null) {
return new EclipseProfile();
}

try {
if (json.startsWith("[\"")) {
var error = objectMapper.readValue(json, TYPE_LIST_STRING);
Expand Down Expand Up @@ -373,6 +377,10 @@ public PublisherAgreement signPublisherAgreement(UserData user) {

private PublisherAgreement parseAgreementResponse(ResponseEntity<String> response) {
var json = response.getBody();
if(json == null) {
return null;
}

try {
PublisherAgreementResponse agreementResponse;
if (json.startsWith("[\"")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private void sortResults(NativeQueryBuilder queryBuilder, String sortOrder, Stri
private long getMaxResultWindow() {
if(maxResultWindow == null) {
var settings = searchOperations.indexOps(ExtensionSearch.class).getSettings(true);
maxResultWindow = Long.parseLong(settings.get("index.max_result_window").toString());
maxResultWindow = Long.parseLong(settings.getOrDefault("index.max_result_window", "10000").toString());
}

return maxResultWindow;
Expand Down

0 comments on commit 6751ab2

Please sign in to comment.