Skip to content

Commit

Permalink
servlet: Check log fine level before hex string conversion. Fixes #11031
Browse files Browse the repository at this point in the history
.
  • Loading branch information
hypnoce authored and ejona86 committed Mar 27, 2024
1 parent 463346c commit 630e0a3
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.locks.LockSupport;
import java.util.function.BiFunction;
import java.util.function.BooleanSupplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -86,6 +87,11 @@ final class AsyncServletOutputStreamWriter {
InternalLogId logId) throws IOException {
Logger logger = Logger.getLogger(AsyncServletOutputStreamWriter.class.getName());
this.log = new Log() {
@Override
public boolean isLoggable(Level level) {
return logger.isLoggable(level);
}

@Override
public void fine(String str, Object... params) {
if (logger.isLoggable(FINE)) {
Expand All @@ -105,7 +111,9 @@ public void finest(String str, Object... params) {
this.writeAction = (byte[] bytes, Integer numBytes) -> () -> {
outputStream.write(bytes, 0, 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 = () -> {
log.finest("flushBuffer");
Expand Down Expand Up @@ -245,6 +253,10 @@ interface ActionItem {

@VisibleForTesting // Lincheck test can not run with java.util.logging dependency.
interface Log {
default boolean isLoggable(Level level) {
return false;
}

default void fine(String str, Object...params) {}

default void finest(String str, Object...params) {}
Expand Down

0 comments on commit 630e0a3

Please sign in to comment.