Skip to content

Commit 4bb8423

Browse files
guanbiaoHuangsnicoll
authored andcommitted
Simplify some code
See spring-projectsgh-17860
1 parent e8effad commit 4bb8423

File tree

7 files changed

+11
-18
lines changed

7 files changed

+11
-18
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/annotation/RequestPredicateFactory.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ private boolean producesResource(Method method) {
123123
}
124124
if (WebEndpointResponse.class.isAssignableFrom(method.getReturnType())) {
125125
ResolvableType returnType = ResolvableType.forMethodReturnType(method);
126-
if (ResolvableType.forClass(Resource.class).isAssignableFrom(returnType.getGeneric(0))) {
127-
return true;
128-
}
126+
return ResolvableType.forClass(Resource.class).isAssignableFrom(returnType.getGeneric(0));
129127
}
130128
return false;
131129
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/Health.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public boolean equals(Object obj) {
8989
if (obj == this) {
9090
return true;
9191
}
92-
if (obj != null && obj instanceof Health) {
92+
if (obj instanceof Health) {
9393
Health other = (Health) obj;
9494
return this.status.equals(other.status) && this.details.equals(other.details);
9595
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/HealthWebEndpointResponseMapper.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,8 @@ private WebEndpointResponse<Health> createWebEndpointResponse(Health health) {
9797
}
9898

9999
private boolean canSeeDetails(SecurityContext securityContext, ShowDetails showDetails) {
100-
if (showDetails == ShowDetails.NEVER || (showDetails == ShowDetails.WHEN_AUTHORIZED
101-
&& (securityContext.getPrincipal() == null || !isUserInRole(securityContext)))) {
102-
return false;
103-
}
104-
return true;
100+
return showDetails != ShowDetails.NEVER && (showDetails != ShowDetails.WHEN_AUTHORIZED
101+
|| (securityContext.getPrincipal() != null && isUserInRole(securityContext)));
105102
}
106103

107104
private boolean isUserInRole(SecurityContext securityContext) {

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/health/Status.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public boolean equals(Object obj) {
107107
if (obj == this) {
108108
return true;
109109
}
110-
if (obj != null && obj instanceof Status) {
110+
if (obj instanceof Status) {
111111
return ObjectUtils.nullSafeEquals(this.code, ((Status) obj).code);
112112
}
113113
return false;

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/info/Info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public boolean equals(Object obj) {
7171
if (obj == this) {
7272
return true;
7373
}
74-
if (obj != null && obj instanceof Info) {
74+
if (obj instanceof Info) {
7575
Info other = (Info) obj;
7676
return this.details.equals(other.details);
7777
}

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/management/PlainTextThreadDumpFormatter.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,7 @@ private void writeStackTraceElement(PrintWriter writer, StackTraceElement elemen
8383
LockInfo lockInfo = info.getLockInfo();
8484
if (firstElement && lockInfo != null) {
8585
if (element.getClassName().equals(Object.class.getName()) && element.getMethodName().equals("wait")) {
86-
if (lockInfo != null) {
87-
writer.printf("\t- waiting on %s%n", format(lockInfo));
88-
}
86+
writer.printf("\t- waiting on %s%n", format(lockInfo));
8987
}
9088
else {
9189
String lockOwner = info.getLockOwnerName();

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AuditEventTests {
3636

3737
@Test
3838
void nowEvent() {
39-
AuditEvent event = new AuditEvent("phil", "UNKNOWN", Collections.singletonMap("a", (Object) "b"));
39+
AuditEvent event = new AuditEvent("phil", "UNKNOWN", Collections.singletonMap("a", "b"));
4040
assertThat(event.getData().get("a")).isEqualTo("b");
4141
assertThat(event.getType()).isEqualTo("UNKNOWN");
4242
assertThat(event.getPrincipal()).isEqualTo("phil");
@@ -52,21 +52,21 @@ void convertStringsToData() {
5252

5353
@Test
5454
void nullPrincipalIsMappedToEmptyString() {
55-
AuditEvent auditEvent = new AuditEvent(null, "UNKNOWN", Collections.singletonMap("a", (Object) "b"));
55+
AuditEvent auditEvent = new AuditEvent(null, "UNKNOWN", Collections.singletonMap("a", "b"));
5656
assertThat(auditEvent.getPrincipal()).isEmpty();
5757
}
5858

5959
@Test
6060
void nullTimestamp() {
6161
assertThatIllegalArgumentException()
62-
.isThrownBy(() -> new AuditEvent(null, "phil", "UNKNOWN", Collections.singletonMap("a", (Object) "b")))
62+
.isThrownBy(() -> new AuditEvent(null, "phil", "UNKNOWN", Collections.singletonMap("a", "b")))
6363
.withMessageContaining("Timestamp must not be null");
6464
}
6565

6666
@Test
6767
void nullType() {
6868
assertThatIllegalArgumentException()
69-
.isThrownBy(() -> new AuditEvent("phil", null, Collections.singletonMap("a", (Object) "b")))
69+
.isThrownBy(() -> new AuditEvent("phil", null, Collections.singletonMap("a", "b")))
7070
.withMessageContaining("Type must not be null");
7171
}
7272

0 commit comments

Comments
 (0)