Skip to content

Commit

Permalink
appease SpotBugs in various places
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaspayette committed Dec 11, 2024
1 parent c3f6080 commit 679c7b5
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import sim.engine.SimState;
import sim.engine.Steppable;
import uk.ac.ox.poseidon.agents.vessels.Vessel;
import uk.ac.ox.poseidon.core.Simulation;
import uk.ac.ox.poseidon.core.schedule.TemporalSchedule;

import java.time.Duration;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -57,7 +57,8 @@ public Action(

@Override
public final void step(final SimState simState) {
final var schedule = ((Simulation) simState).getTemporalSchedule();
checkArgument(simState.schedule instanceof TemporalSchedule);
final var schedule = (TemporalSchedule) simState.schedule;
final var nextAction = complete(schedule.getDateTime());
vessel.getEventManager().broadcast(this);
if (nextAction != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package uk.ac.ox.poseidon.agents.behaviours;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.Getter;
import sim.util.Int2D;
import uk.ac.ox.poseidon.agents.vessels.Vessel;
Expand All @@ -30,6 +31,10 @@
public abstract class GridAction extends Action {
private final Int2D cell;

@SuppressFBWarnings(
value = "EI2",
justification = "Int2D is immutable even if SpotBugs thinks otherwise."
)
public GridAction(
final LocalDateTime start,
final Duration duration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package uk.ac.ox.poseidon.agents.behaviours.choices;

import ec.util.MersenneTwisterFast;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.Optional;
import java.util.function.Supplier;
Expand All @@ -38,6 +39,7 @@ public class EpsilonGreedyChooser<O> implements Supplier<O> {
private O currentOption;
private Evaluation currentEvaluation;

@SuppressFBWarnings(value = "EI2")
public EpsilonGreedyChooser(
final double epsilon,
final MutableOptionValues<O> optionValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package uk.ac.ox.poseidon.agents.behaviours.choices;

import com.google.common.collect.ImmutableList;
import ec.util.MersenneTwisterFast;

import java.util.List;
Expand All @@ -32,7 +33,7 @@

public abstract class MapBasedOptionValues<O> implements OptionValues<O> {

protected List<Map.Entry<O, Double>> cachedBest = null;
protected ImmutableList<Map.Entry<O, Double>> cachedBest = null;

protected abstract Map<O, Double> getValues();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.common.collect.ImmutableList;
import ec.util.MersenneTwisterFast;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.List;
import java.util.Optional;
Expand All @@ -33,6 +34,7 @@ public class RandomPicker<O> implements Picker<O> {
private final ImmutableList<O> options;
private final MersenneTwisterFast rng;

@SuppressFBWarnings(value = "EI2")
public RandomPicker(
final List<O> options,
final MersenneTwisterFast rng
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package uk.ac.ox.poseidon.agents.tables;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import tech.tablesaw.api.DateTimeColumn;
import tech.tablesaw.api.StringColumn;
import tech.tablesaw.api.Table;
Expand Down Expand Up @@ -52,6 +53,10 @@ public void receive(final A action) {
vesselId.append(action.getVessel().getId());
}

@SuppressFBWarnings(
value = "EI",
justification = "Mutable table willfully exposed; just be careful with it."
)
@Override
public Table get() {
return table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ tasks.jacocoTestReport {
html.required.set(true) // HTML report for easier human viewing
}
}

spotbugs {
excludeFilter.set(file("${rootProject.projectDir}/spotbugs_exclude.xml"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package uk.ac.ox.poseidon.core.events;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.util.function.BiFunction;
import java.util.function.Supplier;

Expand All @@ -33,6 +35,7 @@ public class EphemeralAccumulatingListener<E, T>
private T value;
private boolean stillListening = true;

@SuppressFBWarnings("EI2")
public EphemeralAccumulatingListener(
final Class<E> eventClass,
final EventManager eventManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package uk.ac.ox.poseidon.examples.external;

import com.google.common.collect.ImmutableList;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import fishing.BiomassGridServiceGrpc;
import fishing.Fishing;
import sim.engine.SimState;
Expand All @@ -31,6 +32,7 @@

import java.util.List;

@SuppressFBWarnings("Se")
public class ExternalBiomassGridProcess
extends AbstractListener<FishingAction>
implements Steppable {
Expand All @@ -39,6 +41,7 @@ public class ExternalBiomassGridProcess
private final BiomassGridServiceGrpc.BiomassGridServiceBlockingStub stub;
private ImmutableList.Builder<FishingAction> accumulator = new ImmutableList.Builder<>();

@SuppressFBWarnings("EI2")
public ExternalBiomassGridProcess(
final BiomassGrid internalBiomassGrid,
final BiomassGridServiceGrpc.BiomassGridServiceBlockingStub stub
Expand Down
30 changes: 30 additions & 0 deletions spotbugs_exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
~ POSEIDON: an agent-based model of fisheries
~ Copyright (c) 2024 CoHESyS Lab [email protected]
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
~
-->

<FindBugsFilter>
<Match>
<!--
The `fishing` package contains gRPC generated classes that are structured
in ways that SpotBugs finds unholy. The protocol as at the prototype stage
now and the name of the package will change, but we will still have to
exclude it like this down the line.
-->
<Package name="fishing"/>
</Match>
</FindBugsFilter>

0 comments on commit 679c7b5

Please sign in to comment.