JooHyukKim commented on code in PR #20713:
URL: https://github.com/apache/pulsar/pull/20713#discussion_r1251963433
##########
pulsar-broker-common/src/main/java/org/apache/pulsar/broker/ServiceConfigurationUtils.java:
##########
@@ -137,4 +137,18 @@ public static String webServiceUrl(String host, int port) {
public static String webServiceUrlTls(String host, int port) {
return String.format("https://%s:%d", host, port);
}
+
+ public static long getLongPropertyOrDefault(ServiceConfiguration config,
String key, long defaultValue) {
+ Object value = config.getProperties().get(key);
+ if (value instanceof Integer) {
+ return (Long) value;
+ } else if (value instanceof String) {
+ try {
+ return Long.parseLong((String) value);
+ } catch (NumberFormatException e) {
+ return defaultValue;
+ }
+ }
+ return defaultValue;
+ }
Review Comment:
Potential `ClassCastException`. If value is an instance of Integer, I think
it needs to be casted to Integer first and then it can be automatically
promoted to Long.
```suggestion
if (value instanceof Integer) {
return ((Integer) value).longValue();
}
if (value instanceof String) {
try {
return Long.parseLong((String) value);
} catch (NumberFormatException e) {
// Log error, if needed
}
} else if (value != null) {
// Log unexpected type
}
return defaultValue;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]