diff --git a/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java b/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java index 74dbfbedca1..49b47054db2 100644 --- a/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java +++ b/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -119,8 +119,8 @@ final class LogAdapter { public static Log createLocationAwareLog(String name) { Logger logger = LoggerFactory.getLogger(name); - return (logger instanceof LocationAwareLogger ? - new Slf4jLocationAwareLog((LocationAwareLogger) logger) : new Slf4jLog<>(logger)); + return (logger instanceof LocationAwareLogger locationAwareLogger ? + new Slf4jLocationAwareLog(locationAwareLogger) : new Slf4jLog<>(logger)); } public static Log createLog(String name) { @@ -247,14 +247,14 @@ final class LogAdapter { } private void log(Level level, Object message, Throwable exception) { - if (message instanceof String) { + if (message instanceof String text) { // Explicitly pass a String argument, avoiding Log4j's argument expansion // for message objects in case of "{}" sequences (SPR-16226) if (exception != null) { - this.logger.logIfEnabled(FQCN, level, null, (String) message, exception); + this.logger.logIfEnabled(FQCN, level, null, text, exception); } else { - this.logger.logIfEnabled(FQCN, level, null, (String) message); + this.logger.logIfEnabled(FQCN, level, null, text); } } else { @@ -593,8 +593,8 @@ final class LogAdapter { private void log(java.util.logging.Level level, Object message, Throwable exception) { if (this.logger.isLoggable(level)) { LogRecord rec; - if (message instanceof LogRecord) { - rec = (LogRecord) message; + if (message instanceof LogRecord logRecord) { + rec = logRecord; } else { rec = new LocationResolvingLogRecord(level, String.valueOf(message));