Skip to content

Commit f7ee5f3

Browse files
hypnoceejona86
authored andcommitted
servlet: Check log fine level before hex string conversion. Fixes #11031.
1 parent 537dbe8 commit f7ee5f3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

servlet/src/main/java/io/grpc/servlet/AsyncServletOutputStreamWriter.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.concurrent.locks.LockSupport;
3333
import java.util.function.BiFunction;
3434
import java.util.function.BooleanSupplier;
35+
import java.util.logging.Level;
3536
import java.util.logging.Logger;
3637
import javax.annotation.CheckReturnValue;
3738
import javax.annotation.Nullable;
@@ -86,6 +87,11 @@ final class AsyncServletOutputStreamWriter {
8687
InternalLogId logId) throws IOException {
8788
Logger logger = Logger.getLogger(AsyncServletOutputStreamWriter.class.getName());
8889
this.log = new Log() {
90+
@Override
91+
public boolean isLoggable(Level level) {
92+
return logger.isLoggable(level);
93+
}
94+
8995
@Override
9096
public void fine(String str, Object... params) {
9197
if (logger.isLoggable(FINE)) {
@@ -105,7 +111,9 @@ public void finest(String str, Object... params) {
105111
this.writeAction = (byte[] bytes, Integer numBytes) -> () -> {
106112
outputStream.write(bytes, 0, numBytes);
107113
transportState.runOnTransportThread(() -> transportState.onSentBytes(numBytes));
108-
log.finest("outbound data: length={0}, bytes={1}", numBytes, toHexString(bytes, numBytes));
114+
if (log.isLoggable(Level.FINEST)) {
115+
log.finest("outbound data: length={0}, bytes={1}", numBytes, toHexString(bytes, numBytes));
116+
}
109117
};
110118
this.flushAction = () -> {
111119
log.finest("flushBuffer");
@@ -245,6 +253,10 @@ interface ActionItem {
245253

246254
@VisibleForTesting // Lincheck test can not run with java.util.logging dependency.
247255
interface Log {
256+
default boolean isLoggable(Level level) {
257+
return false;
258+
}
259+
248260
default void fine(String str, Object...params) {}
249261

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

0 commit comments

Comments
 (0)