From a4c022ab9ad8fdfc5cc781d6413c7ee64a286ba9 Mon Sep 17 00:00:00 2001 From: Mattias Reichel Date: Mon, 5 Dec 2022 14:47:30 +0100 Subject: [PATCH] Fix nullpointer that happens in exception handler on HttpClientResponseException. (#37) --- grails-app/services/com/bintray/BintrayService.groovy | 11 ++++------- grails-app/services/com/github/GithubService.groovy | 5 ++--- .../grailsplugins/GrailsPluginsService.groovy | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/grails-app/services/com/bintray/BintrayService.groovy b/grails-app/services/com/bintray/BintrayService.groovy index 36b3cba..e1e648b 100644 --- a/grails-app/services/com/bintray/BintrayService.groovy +++ b/grails-app/services/com/bintray/BintrayService.groovy @@ -48,16 +48,15 @@ class BintrayService implements GrailsConfigurationAware { @Deprecated BintrayPackage fetchBintrayPackage(String name, String organization = this.organization, String repository = this.repository) throws IOException { final String url = "/packages/${organization}/${repository}/${name}".toString() - HttpResponse response = null try { log.trace("sending request to {}", url) - response = client + HttpResponse response = client .exchange(HttpRequest.GET(url).basicAuth(username, token), BintrayPackage) log.trace("fetched bintray packages {}", url) return response?.body() } catch(HttpClientResponseException e) { - log.warn 'Response {}. Could not fetch bintray package at {}', response?.status?.code, name + log.warn 'Response {}. Could not fetch bintray package at {}', e.status.code, name } null } @@ -72,9 +71,8 @@ class BintrayService implements GrailsConfigurationAware { String url = UriBuilder.of("/repos/grails/plugins/packages").queryParam("start_pos", startPos).build() log.debug("fetching {}", url) - HttpResponse> response = null try { - response = client.exchange(HttpRequest.GET(url).basicAuth(username, token), Argument.of(List, BintrayPackageSimple)) + def response = client.exchange(HttpRequest.GET(url).basicAuth(username, token), Argument.of(List, BintrayPackageSimple)) log.trace("fetched {}", url) List bintrayPackageList = response?.body() @@ -84,8 +82,7 @@ class BintrayService implements GrailsConfigurationAware { total: totalHeader(response.headers), bintrayPackageList: bintrayPackageList) } catch(HttpClientResponseException e) { - log.warn 'Response {}. Could not fetch bintray packages at {}', response.status.code, startPos - + log.warn 'Response {}. Could not fetch bintray packages at {}', e.status.code, startPos } } diff --git a/grails-app/services/com/github/GithubService.groovy b/grails-app/services/com/github/GithubService.groovy index 3e1a4ce..0a8c066 100644 --- a/grails-app/services/com/github/GithubService.groovy +++ b/grails-app/services/com/github/GithubService.groovy @@ -44,14 +44,13 @@ class GithubService implements GrailsConfigurationAware { return null } final String url = "/repos/${ownerAndRepo}".toString() - HttpResponse response = null try { - response = client.exchange(HttpRequest.GET(url).basicAuth(username, token) + HttpResponse response = client.exchange(HttpRequest.GET(url).basicAuth(username, token) .header("User-Agent", userAgent), GithubRepository) log.trace("fetched {} github repository", ownerAndRepo) return response.body() } catch(HttpClientResponseException e) { - log.warn 'Response {}. Could not fetch github repository at {}', response?.status?.code, vcsUrl + log.warn 'Response {}. Could not fetch github repository at {}', e.status.code, vcsUrl } null } diff --git a/grails-app/services/grailsplugins/GrailsPluginsService.groovy b/grails-app/services/grailsplugins/GrailsPluginsService.groovy index dc096c3..6d19e72 100644 --- a/grails-app/services/grailsplugins/GrailsPluginsService.groovy +++ b/grails-app/services/grailsplugins/GrailsPluginsService.groovy @@ -113,7 +113,7 @@ class GrailsPluginsService implements GrailsConfigurationAware { .forEach({ plugin -> process(plugin) }) } } catch (HttpClientResponseException e) { - log.warn 'Response {}. Could not fetch Grails plugin metadata from Gituhb with error {}', response.status.code, e.message + log.warn 'Response {}. Could not fetch Grails plugin metadata from Gituhb with error {}', e.status.code, e.message } }