Skip to content

Commit

Permalink
update to use assert statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdahlke committed Jan 4, 2024
1 parent 0e26cda commit 0d8f603
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
9 changes: 4 additions & 5 deletions src/main/java/emissary/core/HDMobileAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ protected List<IBaseDataObject> atPlaceHD(final IServiceProviderPlace place, fin
logger.debug("In atPlaceHD {} with {} payload items", place, payloadListArg.size());

List<IBaseDataObject> ret = Collections.emptyList();
TimedResource tr = resourceWatcherStart(place);
try {

try (TimedResource tr = resourceWatcherStart(place)) {
assert tr != null; // to silence an unused resource warning

// Process and get back a list of sprouted payloads
lastPlaceProcessed = place.getDirectoryEntry().getKey();

Expand Down Expand Up @@ -441,9 +443,6 @@ protected List<IBaseDataObject> atPlaceHD(final IServiceProviderPlace place, fin
p.replaceCurrentForm(MobileAgent.ERROR_FORM);
}
} finally {
if (tr != null) {
tr.close();
}
if (!(place instanceof EmptyFormPlace)) {
for (final IBaseDataObject p : payloadListArg) {
if (p.currentFormSize() == 0) {
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/emissary/core/MobileAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ protected void agentControl(final IServiceProviderPlace currentPlaceArg) {
protected void atPlace(final IServiceProviderPlace place, final IBaseDataObject payloadArg) {
logger.debug("In atPlace {} with {}", place, payloadArg.shortName());

TimedResource timer = resourceWatcherStart(place);
try {
try (TimedResource timer = resourceWatcherStart(place)) {
assert timer != null; // to silence an unused resource warning

this.lastPlaceProcessed = place.getDirectoryEntry().getKey();
if (this.moveErrorsOccurred > 0) {
payloadArg.setParameter("AGENT_MOVE_ERRORS", Integer.toString(this.moveErrorsOccurred));
Expand All @@ -358,9 +359,6 @@ protected void atPlace(final IServiceProviderPlace place, final IBaseDataObject
payloadArg.addProcessingError("atPlace(" + place + "): " + problem);
payloadArg.replaceCurrentForm(ERROR_FORM);
} finally {
if (timer != null) {
timer.close();
}
if (!(place instanceof EmptyFormPlace) && payloadArg.currentFormSize() == 0) {
logger.error("Place {} left an empty form stack, changing it to ERROR", place);
payloadArg.addProcessingError(place + " left an empty form stack");
Expand Down Expand Up @@ -397,7 +395,7 @@ protected TimedResource resourceWatcherStart(final IServiceProviderPlace place)
logger.debug("No resource monitoring enabled");
}
}
return tr;
return (tr == null) ? TimedResource.EMPTY : tr;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/emissary/place/CoordinationPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ protected List<IBaseDataObject> coordinate(IBaseDataObject d, boolean hd) {
List<IBaseDataObject> sprouts = null;

// Like an agent would do it
TimedResource tr = resourceWatcherStart(p);
try {
try (TimedResource tr = resourceWatcherStart(p)) {
assert tr != null; // to silence an unused resource warning

if (hd) {
// Do the normal HD processing
sprouts = p.agentProcessHeavyDuty(d);
Expand All @@ -213,9 +214,6 @@ protected List<IBaseDataObject> coordinate(IBaseDataObject d, boolean hd) {
logger.warn("agentProcess {} called from Coordinate problem", (hd ? "HeavyDuty" : "Call"), ex);
errorOccurred = true;
} finally {
if (tr != null) {
tr.close();
}
if (Thread.interrupted()) {
logger.warn("Place {} was interrupted during execution.", p);
}
Expand Down Expand Up @@ -265,7 +263,7 @@ protected TimedResource resourceWatcherStart(final IServiceProviderPlace place)
} catch (EmissaryException ex) {
logger.debug("No resource monitoring enabled");
}
return tr;
return (tr == null) ? TimedResource.EMPTY : tr;
}

/**
Expand Down

0 comments on commit 0d8f603

Please sign in to comment.