Skip to content

Commit 678ea4e

Browse files
committed
Avoid creation of unused logger instance in AbstractMediaTypeExpression
Closes gh-25901
1 parent bacf6ca commit 678ea4e

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
1616

1717
package org.springframework.web.servlet.mvc.condition;
1818

19-
import org.apache.commons.logging.Log;
20-
import org.apache.commons.logging.LogFactory;
21-
2219
import org.springframework.http.MediaType;
2320
import org.springframework.web.bind.annotation.RequestMapping;
2421

@@ -32,8 +29,6 @@
3229
*/
3330
abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Comparable<AbstractMediaTypeExpression> {
3431

35-
protected final Log logger = LogFactory.getLog(getClass());
36-
3732
private final MediaType mediaType;
3833

3934
private final boolean isNegated;
@@ -73,15 +68,15 @@ public int compareTo(AbstractMediaTypeExpression other) {
7368
}
7469

7570
@Override
76-
public boolean equals(Object obj) {
77-
if (this == obj) {
71+
public boolean equals(Object other) {
72+
if (this == other) {
7873
return true;
7974
}
80-
if (obj != null && getClass() == obj.getClass()) {
81-
AbstractMediaTypeExpression other = (AbstractMediaTypeExpression) obj;
82-
return (this.mediaType.equals(other.mediaType) && this.isNegated == other.isNegated);
75+
if (other == null || getClass() != other.getClass()) {
76+
return false;
8377
}
84-
return false;
78+
AbstractMediaTypeExpression otherExpr = (AbstractMediaTypeExpression) other;
79+
return (this.mediaType.equals(otherExpr.mediaType) && this.isNegated == otherExpr.isNegated);
8580
}
8681

8782
@Override
@@ -91,12 +86,10 @@ public int hashCode() {
9186

9287
@Override
9388
public String toString() {
94-
StringBuilder builder = new StringBuilder();
9589
if (this.isNegated) {
96-
builder.append('!');
90+
return '!' + this.mediaType.toString();
9791
}
98-
builder.append(this.mediaType.toString());
99-
return builder.toString();
92+
return this.mediaType.toString();
10093
}
10194

10295
}

0 commit comments

Comments
 (0)