Skip to content

Commit 0f73f46

Browse files
committed
fix more findbugs
1 parent 5a53001 commit 0f73f46

File tree

6 files changed

+98
-8
lines changed

6 files changed

+98
-8
lines changed

src/main/java/com/arpnetworking/configuration/Listener.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.arpnetworking.configuration;
1717

18+
import com.arpnetworking.utility.ConfigurationException;
19+
1820
/**
1921
* Interface for consumers registered for configuration events.
2022
*
@@ -30,11 +32,10 @@ public interface Listener {
3032
* error. Once any listener rejects the {@link Configuration} other
3133
* listeners may not be offered that instance.
3234
*
35+
* @throws ConfigurationException if the {@link Configuration} is rejected.
3336
* @param configuration The new {@link Configuration} to be validated.
34-
* @throws Exception Thrown if the {@link Configuration} should be
35-
* rejected.
3637
*/
37-
void offerConfiguration(Configuration configuration) throws Exception;
38+
void offerConfiguration(Configuration configuration) throws ConfigurationException;
3839

3940
/**
4041
* Invoked to apply the most recently offered configuration. Any

src/main/java/com/arpnetworking/metrics/mad/PeriodWorker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public void postStop() throws Exception {
124124
}
125125

126126
@Override
127-
public void preRestart(final Throwable reason, final Optional<Object> message) throws Exception {
127+
public void preRestart(final Throwable reason, final Optional<Object> message) {
128128
_periodicMetrics.recordCounter("actors/period_worker/restarted", 1);
129129
LOGGER.error()
130130
.setMessage("Restarting")

src/main/java/com/arpnetworking/tsdcore/sinks/HttpPostSinkActor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public void postStop() throws Exception {
141141
_periodicMetrics.recordCounter("actors/http_post_sink/stopped", 1);
142142
}
143143

144+
@SuppressFBWarnings(value = "THROWS_METHOD_THROWS_CLAUSE_BASIC_EXCEPTION", justification = "Super method throws this")
144145
@Override
145146
public void preRestart(final Throwable reason, final Optional<Object> message) throws Exception {
146147
super.preRestart(reason, message);
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2025 Brandon Arp
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.arpnetworking.utility;
17+
18+
import com.arpnetworking.logback.annotations.Loggable;
19+
20+
import java.io.Serial;
21+
22+
/**
23+
* Exception thrown when a configuration error occurs.
24+
*
25+
* @author Brandon Arp (brandon dot arp at inscopemetrics dot io)
26+
*/
27+
@Loggable
28+
public class ConfigurationException extends Exception {
29+
/**
30+
* Public constructor.
31+
*/
32+
public ConfigurationException() {
33+
super();
34+
}
35+
36+
/**
37+
* Public constructor with a description.
38+
*
39+
* @param message Describes the exceptional condition.
40+
*/
41+
public ConfigurationException(final String message) {
42+
super(message);
43+
}
44+
45+
/**
46+
* Public constructor with a description and cause.
47+
*
48+
* @param message Describes the exceptional condition.
49+
* @param cause Causing exception.
50+
*/
51+
public ConfigurationException(final String message, final Throwable cause) {
52+
super(message, cause);
53+
}
54+
55+
/**
56+
* Public constructor with cause.
57+
*
58+
* @param cause Causing exception.
59+
*/
60+
public ConfigurationException(final Throwable cause) {
61+
super(cause);
62+
}
63+
64+
@Serial
65+
private static final long serialVersionUID = 1L;
66+
}

src/main/java/com/arpnetworking/utility/Configurator.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,19 @@ public Configurator(final ConfiguredLaunchableFactory<T, S> factory, final Class
4747
}
4848

4949
@Override
50-
public synchronized void offerConfiguration(final Configuration configuration) throws Exception {
51-
_offeredConfiguration = configuration.getAs(_configurationClass);
50+
public synchronized void offerConfiguration(final Configuration configuration) throws ConfigurationException {
51+
try {
52+
_offeredConfiguration = configuration.getAs(_configurationClass);
53+
// CHECKSTYLE.OFF: IllegalCatch - This exception is explicitly thrown by getAs()
54+
} catch (final RuntimeException e) {
55+
// CHECKSTYLE.ON: IllegalCatch
56+
throw new ConfigurationException(
57+
String.format(
58+
"Unable to parse configuration as %s: %s",
59+
_configurationClass.getCanonicalName(),
60+
e.getMessage()),
61+
e);
62+
}
5263
}
5364

5465
@Override

src/main/java/com/arpnetworking/utility/Reconfigurator.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,19 @@ public Reconfigurator(final Relaunchable<S> relaunchable, final Class<? extends
4747
}
4848

4949
@Override
50-
public synchronized void offerConfiguration(final Configuration configuration) throws Exception {
51-
_offeredConfiguration = configuration.getAs(_configurationClass);
50+
public synchronized void offerConfiguration(final Configuration configuration) throws ConfigurationException {
51+
try {
52+
_offeredConfiguration = configuration.getAs(_configurationClass);
53+
// CHECKSTYLE.OFF: IllegalCatch - This exception is explicitly thrown by getAs()
54+
} catch (final RuntimeException e) {
55+
// CHECKSTYLE.ON: IllegalCatch
56+
throw new ConfigurationException(
57+
String.format(
58+
"Unable to parse configuration as %s: %s",
59+
_configurationClass.getCanonicalName(),
60+
e.getMessage()),
61+
e);
62+
}
5263
}
5364

5465
@Override

0 commit comments

Comments
 (0)