Skip to content

Commit 99d3f90

Browse files
committed
address gemini comments
1 parent 560a31c commit 99d3f90

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/PerConnectionFileHandler.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class PerConnectionFileHandler extends Handler {
3737
private FileHandler defaultHandler;
3838

3939
PerConnectionFileHandler(String baseLogPath, Level level) {
40-
this.baseLogPath = baseLogPath;
40+
this.baseLogPath = baseLogPath != null ? baseLogPath : "";
4141
this.level = level;
4242

4343
try {
@@ -53,7 +53,8 @@ class PerConnectionFileHandler extends Handler {
5353
this.defaultHandler.setLevel(level);
5454
this.defaultHandler.setFormatter(BigQueryJdbcRootLogger.getFormatter());
5555
} catch (IOException e) {
56-
System.err.println("Failed to initialize default log file: " + e.getMessage());
56+
reportError(
57+
"Failed to initialize default log file", e, java.util.logging.ErrorManager.OPEN_FAILURE);
5758
}
5859
}
5960

@@ -86,8 +87,10 @@ public void publish(LogRecord record) {
8687
fh.setFormatter(BigQueryJdbcRootLogger.getFormatter());
8788
return fh;
8889
} catch (IOException e) {
89-
System.err.println(
90-
"Failed to create log file for connection " + id + ": " + e.getMessage());
90+
reportError(
91+
"Failed to create log file for connection " + id,
92+
e,
93+
java.util.logging.ErrorManager.OPEN_FAILURE);
9194
return defaultHandler;
9295
}
9396
});
@@ -108,15 +111,19 @@ public void flush() {
108111
}
109112
}
110113

111-
@Override
112114
@Override
113115
public void close() throws SecurityException {
114116
for (FileHandler h : handlers.values()) {
115-
try { h.close(); } catch (Exception e) {}
117+
try {
118+
h.close();
119+
} catch (Exception e) {
120+
}
116121
}
117122
try {
118123
if (defaultHandler != null) defaultHandler.close();
119-
} finally { handlers.clear(); }
124+
} finally {
125+
handlers.clear();
126+
}
120127
}
121128

122129
public void closeHandler(String connectionId) {

java-bigquery/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/PerConnectionFileHandlerTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131

3232
public class PerConnectionFileHandlerTest {
3333

34-
@TempDir
35-
Path tempDir;
34+
@TempDir Path tempDir;
3635

3736
private PerConnectionFileHandler handler;
3837
private BigQueryConnection mockConnection;
@@ -72,7 +71,7 @@ public void testPublishDefault() throws IOException {
7271
@Test
7372
public void testPublishConnectionSpecific() throws IOException {
7473
BigQueryJdbcMdc.registerInstance(mockConnection, "123");
75-
74+
7675
LogRecord record = new LogRecord(Level.INFO, "Test message connection 123");
7776
handler.publish(record);
7877
handler.flush();
@@ -86,7 +85,7 @@ public void testPublishConnectionSpecific() throws IOException {
8685
@Test
8786
public void testCloseHandler() {
8887
BigQueryJdbcMdc.registerInstance(mockConnection, "456");
89-
88+
9089
LogRecord record = new LogRecord(Level.INFO, "Test message connection 456");
9190
handler.publish(record);
9291
handler.flush();

0 commit comments

Comments
 (0)