From f8bc656921bda3c8d72f943db13710f7d4c5a6d5 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 1 Sep 2020 13:34:08 +0200 Subject: [PATCH] Polish "Removed some redundant 'else's using early return" See gh-22528 --- .../AbstractEndpointDocumentationTests.java | 2 +- .../boot/configurationprocessor/json/JSONObject.java | 12 ++++++++---- .../configurationprocessor/json/JSONTokener.java | 8 +++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AbstractEndpointDocumentationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AbstractEndpointDocumentationTests.java index 9325f1057aff..e496dfb07d29 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AbstractEndpointDocumentationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/AbstractEndpointDocumentationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java index 8c6aae08180c..b7a34606bb65 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONObject.java @@ -596,10 +596,12 @@ public String optString(String name, String fallback) { */ public JSONArray getJSONArray(String name) throws JSONException { Object object = get(name); - if (!(object instanceof JSONArray)) { + if (object instanceof JSONArray) { + return (JSONArray) object; + } + else { throw JSON.typeMismatch(name, object, "JSONArray"); } - return (JSONArray) object; } /** @@ -623,10 +625,12 @@ public JSONArray optJSONArray(String name) { */ public JSONObject getJSONObject(String name) throws JSONException { Object object = get(name); - if (!(object instanceof JSONObject)) { + if (object instanceof JSONObject) { + return (JSONObject) object; + } + else { throw JSON.typeMismatch(name, object, "JSONObject"); } - return (JSONObject) object; } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java index 011c69c02dbf..2a47e73e94ad 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/json-shade/java/org/springframework/boot/configurationprocessor/json/JSONTokener.java @@ -549,13 +549,15 @@ public static int dehexchar(char hex) { if (hex >= '0' && hex <= '9') { return hex - '0'; } - if (hex >= 'A' && hex <= 'F') { + else if (hex >= 'A' && hex <= 'F') { return hex - 'A' + 10; } - if (hex >= 'a' && hex <= 'f') { + else if (hex >= 'a' && hex <= 'f') { return hex - 'a' + 10; } - return -1; + else { + return -1; + } } }