servlet: Check log fine level before hex string conversion. Fixes #11031.

This commit is contained in:
hypnoce 2024-03-22 08:36:46 +01:00 committed by Eric Anderson
parent 537dbe826a
commit f7ee5f3182
1 changed files with 13 additions and 1 deletions

View File

@ -32,6 +32,7 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.LockSupport; import java.util.concurrent.locks.LockSupport;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.annotation.CheckReturnValue; import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -86,6 +87,11 @@ final class AsyncServletOutputStreamWriter {
InternalLogId logId) throws IOException { InternalLogId logId) throws IOException {
Logger logger = Logger.getLogger(AsyncServletOutputStreamWriter.class.getName()); Logger logger = Logger.getLogger(AsyncServletOutputStreamWriter.class.getName());
this.log = new Log() { this.log = new Log() {
@Override
public boolean isLoggable(Level level) {
return logger.isLoggable(level);
}
@Override @Override
public void fine(String str, Object... params) { public void fine(String str, Object... params) {
if (logger.isLoggable(FINE)) { if (logger.isLoggable(FINE)) {
@ -105,7 +111,9 @@ final class AsyncServletOutputStreamWriter {
this.writeAction = (byte[] bytes, Integer numBytes) -> () -> { this.writeAction = (byte[] bytes, Integer numBytes) -> () -> {
outputStream.write(bytes, 0, numBytes); outputStream.write(bytes, 0, numBytes);
transportState.runOnTransportThread(() -> transportState.onSentBytes(numBytes)); transportState.runOnTransportThread(() -> transportState.onSentBytes(numBytes));
log.finest("outbound data: length={0}, bytes={1}", numBytes, toHexString(bytes, numBytes)); if (log.isLoggable(Level.FINEST)) {
log.finest("outbound data: length={0}, bytes={1}", numBytes, toHexString(bytes, numBytes));
}
}; };
this.flushAction = () -> { this.flushAction = () -> {
log.finest("flushBuffer"); log.finest("flushBuffer");
@ -245,6 +253,10 @@ final class AsyncServletOutputStreamWriter {
@VisibleForTesting // Lincheck test can not run with java.util.logging dependency. @VisibleForTesting // Lincheck test can not run with java.util.logging dependency.
interface Log { interface Log {
default boolean isLoggable(Level level) {
return false;
}
default void fine(String str, Object...params) {} default void fine(String str, Object...params) {}
default void finest(String str, Object...params) {} default void finest(String str, Object...params) {}