diff --git a/newrelic-agent/src/main/java/com/newrelic/api/agent/NewRelicApiImplementation.java b/newrelic-agent/src/main/java/com/newrelic/api/agent/NewRelicApiImplementation.java index 83bc8bba07..26900fda3c 100644 --- a/newrelic-agent/src/main/java/com/newrelic/api/agent/NewRelicApiImplementation.java +++ b/newrelic-agent/src/main/java/com/newrelic/api/agent/NewRelicApiImplementation.java @@ -58,9 +58,7 @@ public NewRelicApiImplementation() { */ @Override public void noticeError(Throwable throwable, Map params) { - noticeError(throwable, params, throwable != null && - isExpectedErrorConfigured(throwable.getClass().getName(), throwable.getMessage()), - false); + noticeError(throwable, params, isExpectedErrorConfigured(throwable), false); } /** @@ -72,10 +70,7 @@ public void noticeError(Throwable throwable, Map params) { @Override public void noticeError(Throwable throwable) { Map params = Collections.emptyMap(); - noticeError(throwable, params, throwable != null && - isExpectedErrorConfigured(throwable.getClass().getName(), - throwable.getMessage()), - false); + noticeError(throwable, params, isExpectedErrorConfigured(throwable), false); } @@ -163,19 +158,23 @@ public void noticeError(String message, boolean expected) { noticeError(message, params, expected); } - private boolean isExpectedErrorConfigured(String expectedConfigName, String message) { - boolean expected = true; - String app_name = NewRelic.getAgent().getConfig().getValue("app_name"); - Set expectedErrors = ServiceFactory.getConfigService().getErrorCollectorConfig(app_name).getExpectedErrors(); - for (ExpectedErrorConfig errorConfig : expectedErrors) { - if ((errorConfig.getErrorClass().equals(expectedConfigName) && errorConfig.getErrorMessage() == null) || - (errorConfig.getErrorMessage() != null) && - (errorConfig.getErrorClass().equals(expectedConfigName) && errorConfig.getErrorMessage().equals(message))) { - return expected; + private boolean isExpectedErrorConfigured(Throwable throwable) { + if (throwable != null) { + String expectedConfigName = throwable.getClass().getName(); + String message = throwable.getMessage(); + String app_name = NewRelic.getAgent().getConfig().getValue("app_name"); + Set expectedErrors = ServiceFactory.getConfigService().getErrorCollectorConfig(app_name).getExpectedErrors(); + for (ExpectedErrorConfig errorConfig : expectedErrors) { + String errorClass = errorConfig.getErrorClass(); + String errorMessage = errorConfig.getErrorMessage(); + if ((errorClass.equals(expectedConfigName) && errorMessage == null) || + (errorMessage != null) && + (errorClass.equals(expectedConfigName) && errorMessage.equals(message))) { + return true; + } } } - - return !expected; + return false; } private static Map filterErrorAtts(Map params, AttributeSender attributeSender) {