From a4bb89c72aa6fc8c004a6c7b2c4d1eb1bfdf8f85 Mon Sep 17 00:00:00 2001 From: Daniel Muino Date: Wed, 16 May 2018 15:55:59 -0700 Subject: [PATCH] Update PMD to fix InvalidSlf4jMessageFormat: NPE (#446) Using version 6.3.0 fixes the NPE issue, but had other warnings enabled that were breaking the build. Remove the `ClassNamingConvention` rule which was forcing us to append `Util` to some publicly exposed classes. --- build.gradle | 2 +- codequality/pmd.xml | 10 ++-------- .../servo/publish/apache/ApacheStatusPoller.java | 6 +++--- .../cloudwatch/CloudWatchMetricObserver.java | 1 + .../netflix/servo/tag/aws/AwsInjectableTag.java | 3 +++ .../java/com/netflix/servo/util/Reflection.java | 15 +++++++++++++++ .../com/netflix/servo/example/BaseHandler.java | 1 + .../com/netflix/servo/example/EchoHandler.java | 1 + .../com/netflix/servo/example/ExitHandler.java | 1 + 9 files changed, 28 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index 55bce7ce..b8a1456b 100755 --- a/build.gradle +++ b/build.gradle @@ -112,7 +112,7 @@ subprojects { } pmd { - toolVersion = '5.6.1' + toolVersion = '6.3.0' ignoreFailures = false ruleSets = [] ruleSetFiles = rootProject.files("codequality/pmd.xml") diff --git a/codequality/pmd.xml b/codequality/pmd.xml index cf90d5ad..fb259e45 100644 --- a/codequality/pmd.xml +++ b/codequality/pmd.xml @@ -9,7 +9,6 @@ - @@ -28,6 +27,7 @@ + @@ -43,12 +43,8 @@ - - - - @@ -57,7 +53,7 @@ - + @@ -70,13 +66,11 @@ - - diff --git a/servo-apache/src/main/java/com/netflix/servo/publish/apache/ApacheStatusPoller.java b/servo-apache/src/main/java/com/netflix/servo/publish/apache/ApacheStatusPoller.java index 1504450d..c5cef958 100644 --- a/servo-apache/src/main/java/com/netflix/servo/publish/apache/ApacheStatusPoller.java +++ b/servo-apache/src/main/java/com/netflix/servo/publish/apache/ApacheStatusPoller.java @@ -87,8 +87,8 @@ public InputStream fetchStatus() throws IOException { } } - private static final class StatusPageParser { - private StatusPageParser() { + private static final class StatusPageParserUtil { + private StatusPageParserUtil() { // utility class } @@ -240,7 +240,7 @@ public ApacheStatusPoller(StatusFetcher fetcher) { List pollImpl(long timestamp) { try { try (InputStream statusStream = fetcher.fetchStatus()) { - return StatusPageParser.parse(statusStream, timestamp); + return StatusPageParserUtil.parse(statusStream, timestamp); } } catch (IOException e) { logger.error("Could not fetch status page", e); diff --git a/servo-aws/src/main/java/com/netflix/servo/publish/cloudwatch/CloudWatchMetricObserver.java b/servo-aws/src/main/java/com/netflix/servo/publish/cloudwatch/CloudWatchMetricObserver.java index 979a2637..a686eef1 100644 --- a/servo-aws/src/main/java/com/netflix/servo/publish/cloudwatch/CloudWatchMetricObserver.java +++ b/servo-aws/src/main/java/com/netflix/servo/publish/cloudwatch/CloudWatchMetricObserver.java @@ -176,6 +176,7 @@ public CloudWatchMetricObserver(String name, String namespace, AmazonCloudWatch /** * @param metrics The list of metrics you want to send to CloudWatch */ + @Override public void updateImpl(List metrics) { Preconditions.checkNotNull(metrics, "metrics"); diff --git a/servo-aws/src/main/java/com/netflix/servo/tag/aws/AwsInjectableTag.java b/servo-aws/src/main/java/com/netflix/servo/tag/aws/AwsInjectableTag.java index cb0f9f1b..ee21562b 100644 --- a/servo-aws/src/main/java/com/netflix/servo/tag/aws/AwsInjectableTag.java +++ b/servo-aws/src/main/java/com/netflix/servo/tag/aws/AwsInjectableTag.java @@ -72,6 +72,7 @@ private static Logger getLogger() { /** * @return Amazon compliant string representation of the key. */ + @Override public String getKey() { return key; } @@ -79,10 +80,12 @@ public String getKey() { /** * @return value as determined at runtime for the key. */ + @Override public String getValue() { return value; } + @Override public String tagString() { return key + "=" + value; } diff --git a/servo-core/src/main/java/com/netflix/servo/util/Reflection.java b/servo-core/src/main/java/com/netflix/servo/util/Reflection.java index 38436594..dab1f415 100644 --- a/servo-core/src/main/java/com/netflix/servo/util/Reflection.java +++ b/servo-core/src/main/java/com/netflix/servo/util/Reflection.java @@ -1,3 +1,18 @@ +/** + * Copyright 2018 Netflix, Inc. + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.netflix.servo.util; import java.lang.annotation.Annotation; diff --git a/servo-example/src/main/java/com/netflix/servo/example/BaseHandler.java b/servo-example/src/main/java/com/netflix/servo/example/BaseHandler.java index f45d7a17..83c22a9f 100644 --- a/servo-example/src/main/java/com/netflix/servo/example/BaseHandler.java +++ b/servo-example/src/main/java/com/netflix/servo/example/BaseHandler.java @@ -41,6 +41,7 @@ public void init() { Monitors.registerObject(this); } + @Override public void handle(HttpExchange exchange) throws IOException { CountingInputStream input = new CountingInputStream(exchange.getRequestBody()); CountingOutputStream output = new CountingOutputStream(exchange.getResponseBody()); diff --git a/servo-example/src/main/java/com/netflix/servo/example/EchoHandler.java b/servo-example/src/main/java/com/netflix/servo/example/EchoHandler.java index a67938a2..c9d07de1 100644 --- a/servo-example/src/main/java/com/netflix/servo/example/EchoHandler.java +++ b/servo-example/src/main/java/com/netflix/servo/example/EchoHandler.java @@ -27,6 +27,7 @@ public EchoHandler() { init(); } + @Override protected void handleImpl(HttpExchange exchange) throws IOException { exchange.sendResponseHeaders(200, 0); ByteStreams.copy(exchange.getRequestBody(), exchange.getResponseBody()); diff --git a/servo-example/src/main/java/com/netflix/servo/example/ExitHandler.java b/servo-example/src/main/java/com/netflix/servo/example/ExitHandler.java index ec1ce796..78aff979 100644 --- a/servo-example/src/main/java/com/netflix/servo/example/ExitHandler.java +++ b/servo-example/src/main/java/com/netflix/servo/example/ExitHandler.java @@ -30,6 +30,7 @@ public ExitHandler(Closeable server) { init(); } + @Override protected void handleImpl(HttpExchange exchange) throws IOException { try { exchange.sendResponseHeaders(200, 0);