Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -184,6 +185,7 @@ public boolean shouldRetry(IOException e) {
return RetryDeterminer.SOCKET_ERRORS.shouldRetry(e);
}
};
private static final AtomicBoolean overwriteLog = new AtomicBoolean(false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The java.util.logging.LogManager only maintains weak references to loggers. If a logger is not held by a strong reference, it can be garbage collected, and any configuration changes (such as the log level) will be lost. To ensure the suppression persists, store the logger in a static field.

Suggested change
private static final AtomicBoolean overwriteLog = new AtomicBoolean(false);
private static final java.util.logging.Logger GCS_IO_LOGGER =
java.util.logging.Logger.getLogger("com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl");
private static final AtomicBoolean overwriteLog = new AtomicBoolean(false);


/////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -726,9 +728,16 @@ public WritableByteChannel create(GcsPath path, CreateOptions options) throws IO
}
}

@SuppressFBWarnings("LG_LOST_LOGGER_DUE_TO_WEAK_REFERENCE")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This suppression is unnecessary if a strong reference to the logger is maintained in a static field. It is better to address the underlying issue of the weak reference than to suppress the warning.

GoogleCloudStorage createGoogleCloudStorage(
GoogleCloudStorageOptions options, Storage storage, Credentials credentials)
throws IOException {
// Suppress log spams in gcsio 3.0
if (overwriteLog.compareAndSet(false, true)) {
java.util.logging.Logger.getLogger("com.google.cloud.hadoop.gcsio.GoogleCloudStorageImpl")
.setLevel(java.util.logging.Level.SEVERE);
}
Comment on lines +736 to +739
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Use the static logger field to set the log level. This ensures that the SEVERE level setting is preserved even if the logger is internally recreated by the LogManager.

    if (overwriteLog.compareAndSet(false, true)) {
      GCS_IO_LOGGER.setLevel(java.util.logging.Level.SEVERE);
    }


return GoogleCloudStorageImpl.builder()
.setOptions(options)
.setHttpTransport(storage.getRequestFactory().getTransport())
Expand Down
Loading