From 40be903728b252c3014746c1f9dec82bed257177 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Wed, 8 Nov 2017 15:30:03 +0100 Subject: [PATCH 1/3] Wrap fileDescriptorRatioGauge which breaks in java9 Java9 fails with `InaccessibleObjectException` which causes all metric reporting to fail. This is a new exception in java9 so we can't catch it in Java8, simply return 0 if exception is thrown. This is tested in java8/java9 ``` java.lang.reflect.InaccessibleObjectException: Unable to make public long com.sun.management.internal.OperatingSystemImpl.getOpenFileDescriptorCount() accessible: module jdk.management does not "opens com.sun.management.internal" to unnamed module @385c9627 ``` --- .../com/spotify/metrics/jvm/FileDescriptorGaugeSet.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java b/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java index c6497c8..8bb8d9a 100644 --- a/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java +++ b/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java @@ -51,7 +51,13 @@ public Map getMetrics() { gauges.put(metricId, new Gauge() { @Override public Object getValue() { - return fileDescriptorRatioGauge.getValue(); + // Java 9 will throw java.lang.reflect.InaccessibleObjectException + // which does not exist in Java 8, therefore return 0. + try { + return fileDescriptorRatioGauge.getValue(); + } catch(Exception e) { + return 0; + } } }); return Collections.unmodifiableMap(gauges); From 21c1241bba99306765cb5073024ab51292d96cc3 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Wed, 8 Nov 2017 15:43:33 +0100 Subject: [PATCH 2/3] fix lint --- .../java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java b/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java index 8bb8d9a..00099ed 100644 --- a/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java +++ b/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java @@ -55,7 +55,7 @@ public Object getValue() { // which does not exist in Java 8, therefore return 0. try { return fileDescriptorRatioGauge.getValue(); - } catch(Exception e) { + } catch (Exception e) { return 0; } } From c55d0cd747496972aae721b6de33a9b3bac1512d Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Wed, 8 Nov 2017 15:53:05 +0100 Subject: [PATCH 3/3] make Exception final --- .../java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java b/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java index 00099ed..d709dd2 100644 --- a/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java +++ b/core/src/main/java/com/spotify/metrics/jvm/FileDescriptorGaugeSet.java @@ -55,7 +55,7 @@ public Object getValue() { // which does not exist in Java 8, therefore return 0. try { return fileDescriptorRatioGauge.getValue(); - } catch (Exception e) { + } catch (final Exception e) { return 0; } }