Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

servlet: Check log fine level before hex string conversion. Fixes #11031. (1.63.x backport) #11038

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
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 @@
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));

Check warning on line 115 in servlet/src/main/java/io/grpc/servlet/AsyncServletOutputStreamWriter.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L115 was not covered by tests
}
};
this.flushAction = () -> {
log.finest("flushBuffer");
Expand Down Expand Up @@ -245,6 +253,10 @@

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

Check warning on line 257 in servlet/src/main/java/io/grpc/servlet/AsyncServletOutputStreamWriter.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L257 was not covered by tests
}

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

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