Skip to content

Commit

Permalink
errorprone :: CatchingUnchecked
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb committed Oct 27, 2024
1 parent 76550b7 commit 3aaaa4b
Show file tree
Hide file tree
Showing 31 changed files with 52 additions and 63 deletions.
1 change: 1 addition & 0 deletions src/main/java/emissary/Emissary.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected Emissary(Map<String, EmissaryCommand> cmds) {
}
}

@SuppressWarnings("CatchingUnchecked")
protected void execute(String[] args) {
reconfigureLogHook(); // so we can capture everything for test, like the verbose output
String shouldSetVerbose = System.getProperty("set.picocli.debug");
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/emissary/client/EmissaryResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,12 @@ public String getContentString() {
if (content == null) {
return null;
}
try {
if (status == HttpStatus.SC_OK) {
return content.toString();
} else {
return "Bad request -> status: " + status + " message: " + content;
}
} catch (Exception e) {
logger.error("Error getting string content", e);
return e.getMessage();
}

if (status == HttpStatus.SC_OK) {
return content.toString();
} else {
return "Bad request -> status: " + status + " message: " + content;
}
}

public <T extends BaseEntity> T getContent(Class<T> mapper) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/command/MonitorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void sendClusterRequests(final EmissaryClient client, final T entity) th
synchronized (lock) {
entity.append(response);
}
} catch (Exception e) {
} catch (RuntimeException e) {
LOG.error("Problem hitting agents endpoint: {}\n{}", hostAndPort, e.getMessage());
synchronized (lock) {
entity.addError(e.getMessage());
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/emissary/command/TopologyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ public void run(CommandLine c) {
String endpoint = getScheme() + "://" + getHost() + ":" + getPort() + "/api/cluster/peers";
LOG.info("Hitting " + endpoint);
EmissaryClient client = new EmissaryClient();
try {
PeersResponseEntity entity = client.send(new HttpGet(endpoint)).getContent(PeersResponseEntity.class);
entity.dumpToConsole();
} catch (Exception e) {
LOG.error("Problem hitting peers endpoint: " + e.getMessage());
}
PeersResponseEntity entity = client.send(new HttpGet(endpoint)).getContent(PeersResponseEntity.class);
entity.dumpToConsole();
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/config/ServiceConfigGuide.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ protected String substituteUtfChars(final String s, final String filename, final
final int digit = Integer.parseInt(s.substring(i + 2, epos), 16);
sb.appendCodePoint(digit);
i = epos - 1;
} catch (Exception ex) {
} catch (RuntimeException ex) {
throw new IOException("Unable to convert characters in " + s + ", from filename=" + filename + " line " + lnum, ex);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/core/MobileAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void killAgentAsync() {
try {
this.thread.setPriority(Thread.MIN_PRIORITY);
this.thread.interrupt();
} catch (Exception ignored) {
} catch (RuntimeException ignored) {
// empty catch block
}
}
Expand Down Expand Up @@ -619,7 +619,7 @@ protected DirectoryEntry nextKeyFromDirectory(final String dataId, final IServic
logger.debug("Added {} new key entries from the directory for {}", entries.size(), dataId);
}

} catch (Exception e) {
} catch (RuntimeException e) {
logger.warn("cannot get key, I was working on: {}", payloadArg.shortName(), e);
// Returning instead of throwing will allow
// the next form to be tried.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/core/TimedResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void interruptAgent() {
LOG.debug("Found agent that needs interrupting {} in place {}", agent.getName(), placeName);
agent.interrupt();
}
} catch (Exception e) {
} catch (RuntimeException e) {
LOG.error("Unable to interrupt agent {}: {}", agent.getName(), e.getMessage(), e);
} finally {
lock.unlock();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/core/sentinel/Sentinel.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected void init() {
} else {
logger.debug("Sentinel protocol disabled {}", protocol);
}
} catch (Exception e) {
} catch (RuntimeException e) {
logger.warn("Unable to configure Sentinel Protocol[{}]: {}", protocolConfig, e.getMessage());
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/emissary/directory/DirectoryPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ protected void sendFailMessage(final DirectoryEntry directory, final String fail

try {
new DirectoryAdapter().outboundFailDirectory(directory.getKey(), failKey, permanent);
} catch (Exception ex) {
} catch (RuntimeException ex) {
logger.error("Problem talking to directory {} to fail {}", directory.getKey(), failKey, ex);
}
}
Expand Down Expand Up @@ -931,7 +931,7 @@ protected void registerWith(final DirectoryEntry dir, final List<DirectoryEntry>
try {
new DirectoryAdapter().outboundAddPlaces(dir.getKey(), entryList, propagating);
logger.debug("registration succeeded");
} catch (Exception ex) {
} catch (RuntimeException ex) {
logger.warn("DirectoryPlace.registerWith: Problem talking to directory {} to add {} entries", dir.getKey(), entryList.size(), ex);
}
}
Expand Down Expand Up @@ -1269,7 +1269,7 @@ protected void deregisterFrom(final DirectoryEntry dir, final List<String> keys,
try {
// Follow the logic to irdRemovePlaces on the remote side
new DirectoryAdapter().outboundRemovePlaces(dir.getKey(), keys, propagating);
} catch (Exception ex) {
} catch (RuntimeException ex) {
logger.error("DirectoryPlace.deregisterFrom: " + "Problem talking to directory " + dir.getKey() + " to deregister keys", ex);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/directory/HeartbeatManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void run() {
heartbeat(dir);
}
logger.debug("Ending the HeartbeatTask run method");
} catch (Exception e) {
} catch (RuntimeException e) {
logger.error("Unexpected problem in heartbeat timer", e);
}
}
Expand All @@ -345,7 +345,7 @@ public final boolean heartbeat(final String key) {
healthReport(key, false, response.getContentString());
isup = false;
}
} catch (Exception e) {
} catch (RuntimeException e) {
logger.error("Cannot perform heartbeat", e);
healthReport(key, false, e.getMessage());
isup = false;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/jni/JNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* wishing to loadLibraries from the JniRepositoryPlace should include this class via composition and invoke
* this.loadLibrary rather than System.loadLibrary()
*/
@SuppressWarnings("CatchingUnchecked")
public class JNI implements Serializable {

static final long serialVersionUID = 3037911106823343480L;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/kff/KffChainLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static int loadFrom(KffChain chain, Map<String, String> m, FilterType fi
KffFilter k;
try {
k = (KffFilter) Factory.create(clazz, name, key, filterType);
} catch (Exception x) {
} catch (RuntimeException x) {
logger.warn("Cannot create KffFilter, using default", x);
k = new KffFile(name, key, filterType);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/emissary/output/DropOffPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected void initializeFilters(final List<String> filterClasses) {
} else {
logger.error("Misconfigured filter {} is not an IDropOffFilter instance, ignoring it", clazz);
}
} catch (Exception ex) {
} catch (RuntimeException ex) {
logger.error("Unable to create or initialize {}", clazz, ex);
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ public List<IBaseDataObject> agentProcessHeavyDuty(final List<IBaseDataObject> p

// Process the payload item with HDcontext=true
processData(d, true);
} catch (Exception e) {
} catch (RuntimeException e) {
logger.error("Place.process threw:", e);
d.addProcessingError("agentProcessHD(" + myKey + "): " + e);

Expand Down Expand Up @@ -435,7 +435,7 @@ protected void runOutputFilters(final Object target, final Map<String, Object> f
filterStatus = IDropOffFilter.STATUS_SUCCESS;
}
logger.debug("Filter {} took {}s - {}", filter.getFilterName(), ((System.currentTimeMillis() - start) / 1000.0), filterStatus);
} catch (Exception e) {
} catch (RuntimeException e) {
logger.error("Filter {} failed", filter.getFilterName(), e);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/parser/ParserFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected SessionParser makeSessionParserClass(@Nullable String clazz, Object...

try {
sp = (SessionParser) Factory.create(clazz, args);
} catch (Exception e) {
} catch (RuntimeException e) {
logger.error("Unable to instantiate {}", clazz, e);
}

Expand All @@ -190,7 +190,7 @@ protected void makeIdEngine(String clazz) {
try {
DataIdentifier d = (DataIdentifier) Factory.create(clazz);
idEngine = d;
} catch (Exception ex) {
} catch (RuntimeException ex) {
logger.warn("Cannot make data identifier from " + clazz, ex);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/pickup/PickUpSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public boolean take() {
WorkBundle path = null;
try {
path = tpa.outboundWorkSpaceTake(openSpaceName, myKey);
} catch (Exception ex) {
} catch (RuntimeException ex) {
logger.error("Failed to take work from " + openSpaceName, ex);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/pickup/QueServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void run() {
// Process something on the queue
try {
checkQue();
} catch (Exception e) {
} catch (RuntimeException e) {
logger.warn("Exception in checkQue():" + e, e);
}

Expand Down Expand Up @@ -131,7 +131,7 @@ public void checkQue() {
boolean status = processQueueItem(paths);
logger.debug("Initiating bundle completed msg for {}, status={}", paths.getBundleId(), status);
space.bundleCompleted(paths.getBundleId(), status);
} catch (Exception e) {
} catch (RuntimeException e) {
StringBuilder fnb = new StringBuilder();
// Report filenames on error
for (Iterator<String> i = paths.getFileNameIterator(); i.hasNext();) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/place/CoordinationPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected void configurePlace() {
failedCoordPlaceCreation.add(s + " in " + configG.findStringEntry("PLACE_NAME"));
logger.error("Place does not exist and cannot be created: {}", s);
}
} catch (Exception e) {
} catch (RuntimeException e) {
failedCoordPlaceCreation.add(s + " in " + configG.findStringEntry("PLACE_NAME"));
logger.error("Place does not exist and cannot be created: {}", s, e);
}
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/emissary/place/MultiFileUnixCommandPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,8 @@ protected List<IBaseDataObject> processData(@Nullable IBaseDataObject tData, int
if (files != null && !files.isEmpty()) {
sprouts = sproutResults(tData, files, f.getParent(), parentData);
}
} catch (Exception ex) {
} catch (RuntimeException ex) {
logger.error("Problem in command execution", ex);
if (ex instanceof InterruptedException) {
throw new ResourceException(ex); // framework notification to stop
}
} finally {
// Delete the temporary directory and all of its contents.
if (f != null) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/emissary/place/ServiceProviderPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public void agentProcessCall(IBaseDataObject payload) throws ResourceException {
rehash(payload);
} catch (ResourceException r) {
throw r;
} catch (Exception e) {
} catch (RuntimeException e) {
logger.error("Place.process exception", e);
}
}
Expand Down Expand Up @@ -898,7 +898,7 @@ protected void registerWithDirectory(List<String> keylist) {
logger.debug("Registering my {} keys {}", keylist.size(), keylist);
localDirPlace.addPlaces(keylist);
}
} catch (Exception e) {
} catch (RuntimeException e) {
logger.warn("Register ERROR for keys {}", keylist, e);
}
}
Expand All @@ -921,7 +921,7 @@ protected void deregisterFromDirectory(List<String> keys) {
logger.debug("Deregistering my {} proxies {}", keys.size(), keys);
localDirPlace.removePlaces(keys);
}
} catch (Exception e) {
} catch (RuntimeException e) {
logger.warn("Deregister ERROR keys={}", keys, e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/pool/AgentPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ protected void emptyPool() {
try {
// destroys the object, needed to decrement the numIdle
returnAgent(a);
} catch (Exception e) {
} catch (RuntimeException e) {
logger.error("Error trying to returnAgent: {}", a.getName(), e);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/pool/MoveSpool.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void run() {
logger.error("Unable to start agent, payload " + itemName + " is irretrievably lost", t);
try {
pool.returnAgent(agent);
} catch (Exception ex) {
} catch (RuntimeException ex) {
logger.error("Unable to return agent to the pool", ex);
}
} else {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/pool/PayloadLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class PayloadLauncher {
private static final Logger logger = LoggerFactory.getLogger(PayloadLauncher.class);


@SuppressWarnings("CatchingUnchecked")
public static boolean launch(Object payload, IServiceProviderPlace place, int errorCount, List<DirectoryEntry> itineraryItems)
throws EmissaryException {
String payloadName = PayloadUtil.getName(payload);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/roll/RollManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void init(Configurator configG) {
try {
Map<String, String> map = configG.findStringMatchMap(roller + "_");
cfgRollers.add(RollUtil.buildRoller(map));
} catch (Exception e) {
} catch (RuntimeException e) {
log.warn("Unable to configure Rollable for: {}", roller);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/server/api/Shutdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ protected Response shutdown(HttpServletRequest request, boolean force) {
} else {
EmissaryServer.stopServer();
}
} catch (Exception e) {
} catch (RuntimeException e) {
// swallow
}
System.exit(0);
}).start();
return Response.ok("Shutdown initiated. Come again soon!").build();
} catch (Exception e) {
} catch (RuntimeException e) {
LOG.warn("Exception trying to initiate shutdown: {}", e.getMessage());
return Response.serverError().entity("Error trying to initiate shutdown").build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package emissary.server.mvc.internal;

import emissary.core.Namespace;
import emissary.core.NamespaceException;
import emissary.core.ResourceWatcher;
import emissary.output.DropOffPlace;
import emissary.output.filter.IDropOffFilter;
Expand Down Expand Up @@ -39,7 +40,7 @@ public Response rollOutputs(@QueryParam("filter") List<String> outputFilterNames
f.close();
outputNames.append(" ").append(filter);
}
} catch (Exception ex) {
} catch (RuntimeException ex) {
outputNames.append(" ").append(filter).append("-FAILED");
logger.error("Could not roll " + filter, ex);
}
Expand All @@ -53,7 +54,7 @@ public Response rollOutputs(@QueryParam("filter") List<String> outputFilterNames
}

return Response.ok().entity("Output Rolled: " + outputNames).build();
} catch (Exception ex) {
} catch (NamespaceException | RuntimeException ex) {
logger.warn("Could not roll outputs", ex);
return Response.ok().entity("Could not roll outputs: " + ex.toString()).build();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emissary/transform/decode/HtmlEscape.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.annotation.Nullable;

@Deprecated(forRemoval = true)
@SuppressWarnings("all")
public class HtmlEscape {

/* our logger */
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/emissary/util/CharsetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static boolean isAscii(final String s) {
return false;
}
}
} catch (Exception e) {
} catch (RuntimeException e) {
return false;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/emissary/util/DateTimeFormatParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected static void configure() {
}
try {
zone = ZoneId.of(configG.findStringEntry("TIME_ZONE"));
} catch (Exception e) {
} catch (RuntimeException e) {
logger.error("There was an issue reading the time zone from the config file");
return;
}
Expand Down Expand Up @@ -88,7 +88,7 @@ private static void loadDateTimeEntries(Configurator configG, String entryType,
}
final DateTimeFormatter dtf = initialDtf;
dateFormats.add(dtf);
} catch (Exception ex) {
} catch (RuntimeException ex) {
logger.debug("{} entry '{}' cannot be parsed", entryType, dateFormatEntry, ex);
}
}
Expand Down
Loading

0 comments on commit 3aaaa4b

Please sign in to comment.