Gracefully handle invalid port value in config
Change-Id: Ie6a02d0663c835c120b7da29658dbb1e79ec3149
diff --git a/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritGraphiteReporter.java b/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritGraphiteReporter.java
index f8d1147..ab15709 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritGraphiteReporter.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/metricsreporters/GerritGraphiteReporter.java
@@ -65,7 +65,13 @@
Config config = configFactory.getGlobalPluginConfig(pluginName);
String host = firstNonNull(
config.getString(SECTION_GRAPHITE, null, KEY_HOST), DEFAULT_HOST);
- int port = config.getInt(SECTION_GRAPHITE, KEY_PORT, DEFAULT_PORT);
+ int port;
+ try {
+ port = config.getInt(SECTION_GRAPHITE, KEY_PORT, DEFAULT_PORT);
+ } catch (IllegalArgumentException e) {
+ log.warn(String.format("Invalid port value; default to %d", DEFAULT_PORT));
+ port = DEFAULT_PORT;
+ }
String prefix = config.getString(SECTION_GRAPHITE, null, KEY_PREFIX);
if (prefix == null) {
try {