From 678ea4ece7e2c2ede680e0b2cecb1cafc1c8fbe6 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 13 Oct 2020 01:20:34 +0200 Subject: [PATCH] Avoid creation of unused logger instance in AbstractMediaTypeExpression Closes gh-25901 --- .../AbstractMediaTypeExpression.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java index 8561cb490b..1b225438b0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-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. @@ -16,9 +16,6 @@ package org.springframework.web.servlet.mvc.condition; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; @@ -32,8 +29,6 @@ import org.springframework.web.bind.annotation.RequestMapping; */ abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Comparable { - protected final Log logger = LogFactory.getLog(getClass()); - private final MediaType mediaType; private final boolean isNegated; @@ -73,15 +68,15 @@ abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Compa } @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (obj != null && getClass() == obj.getClass()) { - AbstractMediaTypeExpression other = (AbstractMediaTypeExpression) obj; - return (this.mediaType.equals(other.mediaType) && this.isNegated == other.isNegated); + if (other == null || getClass() != other.getClass()) { + return false; } - return false; + AbstractMediaTypeExpression otherExpr = (AbstractMediaTypeExpression) other; + return (this.mediaType.equals(otherExpr.mediaType) && this.isNegated == otherExpr.isNegated); } @Override @@ -91,12 +86,10 @@ abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Compa @Override public String toString() { - StringBuilder builder = new StringBuilder(); if (this.isNegated) { - builder.append('!'); + return '!' + this.mediaType.toString(); } - builder.append(this.mediaType.toString()); - return builder.toString(); + return this.mediaType.toString(); } }