Skip to content

Commit 11dcb7b

Browse files
Copilotahmedmuhsin
andcommitted
Address code review feedback: optimize logger instantiation and null handling
- Move logger to static final class member for efficiency - Add null checks for getDescription() to preserve fallback values - All tests still pass successfully Co-authored-by: ahmedmuhsin <36454324+ahmedmuhsin@users.noreply.github.com>
1 parent e115414 commit 11dcb7b

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/main/java/com/microsoft/azure/functions/worker/JavaWorkerClient.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* Thread-Safety: Single thread.
2121
*/
2222
public class JavaWorkerClient implements AutoCloseable {
23+
private static final Logger logger = Logger.getLogger(JavaWorkerClient.class.getName());
24+
2325
public JavaWorkerClient(IApplication app) {
2426
WorkerLogManager.initialize(this, app.logToConsole());
2527
ManagedChannelBuilder<?> chanBuilder = ManagedChannelBuilder.forAddress(app.getHost(), app.getPort()).usePlaintext();
@@ -101,18 +103,23 @@ public void onNext(StreamingMessage message) {
101103

102104
@Override
103105
public void onError(Throwable t) {
104-
Logger logger = Logger.getLogger(JavaWorkerClient.class.getName());
105106
String statusCode = "Unknown";
106107
String statusDescription = t.getMessage();
107108

108109
if (t instanceof io.grpc.StatusRuntimeException) {
109110
io.grpc.StatusRuntimeException sre = (io.grpc.StatusRuntimeException) t;
110111
statusCode = sre.getStatus().getCode().name();
111-
statusDescription = sre.getStatus().getDescription();
112+
String description = sre.getStatus().getDescription();
113+
if (description != null) {
114+
statusDescription = description;
115+
}
112116
} else if (t instanceof io.grpc.StatusException) {
113117
io.grpc.StatusException se = (io.grpc.StatusException) t;
114118
statusCode = se.getStatus().getCode().name();
115-
statusDescription = se.getStatus().getDescription();
119+
String description = se.getStatus().getDescription();
120+
if (description != null) {
121+
statusDescription = description;
122+
}
116123
}
117124

118125
logger.severe(String.format(

0 commit comments

Comments
 (0)