draft: Address false positives in code style issues (#3461)

* chore: Address false positive code style issues

* chore: More work

* More work
This commit is contained in:
Alex 2022-01-20 12:39:40 +01:00 committed by GitHub
parent 6f4d2f6d5a
commit 827f46566c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 30 additions and 13 deletions

4
.lift.toml Normal file
View File

@ -0,0 +1,4 @@
jdkVersion = "17"
build = "gradle clean build -x test"
tools = ["findsecbugs", "ErrorProne", "Semgrep", "Detekt", "Infer"]
ignoreRules = ["CatchAndPrintStackTrace", "ReferenceEquality", "FallThrough", "FutureReturnValueIgnored", "MixedMutabilityReturnType", "EmptyCatch", "MissingCasesInEnumSwitch", "OperatorPrecedence", "StaticAssignmentInConstructor", "ReferenceEquality", "EqualsHashCode", "EqualsGetClass", "TypeParameterUnusedInFormals"]

View File

@ -218,6 +218,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
private PlatformWorldManager<World> worldManager; private PlatformWorldManager<World> worldManager;
private Locale serverLocale; private Locale serverLocale;
@SuppressWarnings("StringSplitter")
@Override @Override
public int @NonNull [] serverVersion() { public int @NonNull [] serverVersion() {
if (this.version == null) { if (this.version == null) {
@ -970,7 +971,6 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
} }
iterator.remove(); iterator.remove();
entity.remove(); entity.remove();
continue;
} }
} }
} else { } else {
@ -982,7 +982,6 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
} }
iterator.remove(); iterator.remove();
entity.remove(); entity.remove();
continue;
} }
} }
} }
@ -1223,7 +1222,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl
@Override @Override
@NonNull @NonNull
@SuppressWarnings("ALL") @SuppressWarnings("unchecked")
public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> playerManager() { public PlayerManager<? extends PlotPlayer<Player>, ? extends Player> playerManager() {
return (PlayerManager<BukkitPlayer, Player>) injector().getInstance(PlayerManager.class); return (PlayerManager<BukkitPlayer, Player>) injector().getInstance(PlayerManager.class);
} }

View File

@ -461,6 +461,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.tamed.tamed = tamed.isTamed(); this.tamed.tamed = tamed.isTamed();
} }
@SuppressWarnings("deprecation") // Paper deprecation
@Override @Override
public Entity spawn(World world, int xOffset, int zOffset) { public Entity spawn(World world, int xOffset, int zOffset) {
Location location = new Location(world, this.getX() + xOffset, this.getY(), this.z + zOffset); Location location = new Location(world, this.getX() + xOffset, this.getY(), this.z + zOffset);

View File

@ -36,6 +36,7 @@ import org.bukkit.World;
public class WorldManagerModule extends AbstractModule { public class WorldManagerModule extends AbstractModule {
@SuppressWarnings("removal") // Internal use only
@Provides @Provides
@Singleton @Singleton
PlatformWorldManager<World> provideWorldManager() { PlatformWorldManager<World> provideWorldManager() {

View File

@ -36,7 +36,6 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.text.minimessage.Template;
import org.bukkit.block.Banner; import org.bukkit.block.Banner;
import org.bukkit.block.Beacon; import org.bukkit.block.Beacon;
import org.bukkit.block.Bed;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.CommandBlock; import org.bukkit.block.CommandBlock;
import org.bukkit.block.Comparator; import org.bukkit.block.Comparator;
@ -51,6 +50,7 @@ import org.bukkit.block.Jukebox;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.block.Skull; import org.bukkit.block.Skull;
import org.bukkit.block.Structure; import org.bukkit.block.Structure;
import org.bukkit.block.data.type.Bed;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;

View File

@ -224,6 +224,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
} }
} }
@SuppressWarnings("StringSplitter")
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void playerCommand(PlayerCommandPreprocessEvent event) { public void playerCommand(PlayerCommandPreprocessEvent event) {
String msg = event.getMessage().toLowerCase().replaceAll("/", "").trim(); String msg = event.getMessage().toLowerCase().replaceAll("/", "").trim();
@ -379,6 +380,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
this.eventDispatcher.doRespawnTask(pp); this.eventDispatcher.doRespawnTask(pp);
} }
@SuppressWarnings("deprecation") // We explicitly want #getHomeSynchronous here
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) { public void onTeleport(PlayerTeleportEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -1667,6 +1669,7 @@ public class PlayerEventListener extends PlotListener implements Listener {
} }
} }
@SuppressWarnings("deprecation") // #getLocate is needed for Spigot compatibility
@EventHandler @EventHandler
public void onLocaleChange(final PlayerLocaleChangeEvent event) { public void onLocaleChange(final PlayerLocaleChangeEvent event) {
// The event is fired before the player is deemed online upon login // The event is fired before the player is deemed online upon login

View File

@ -43,7 +43,6 @@ import java.lang.reflect.Method;
import static com.plotsquared.core.util.ReflectionUtils.getRefClass; import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
@SuppressWarnings("unused")
public class SingleWorldListener implements Listener { public class SingleWorldListener implements Listener {
private final Method methodGetHandleChunk; private final Method methodGetHandleChunk;

View File

@ -162,6 +162,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
} }
} }
@SuppressWarnings("StringSplitter")
@Override @Override
@NonNegative @NonNegative
public int hasPermissionRange( public int hasPermissionRange(
@ -319,7 +320,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
if (id == ItemTypes.AIR) { if (id == ItemTypes.AIR) {
// Let's just stop all the discs because why not? // Let's just stop all the discs because why not?
for (final Sound sound : Arrays.stream(Sound.values()) for (final Sound sound : Arrays.stream(Sound.values())
.filter(sound -> sound.name().contains("DISC")).collect(Collectors.toList())) { .filter(sound -> sound.name().contains("DISC")).toList()) {
player.stopSound(sound); player.stopSound(sound);
} }
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, Material.AIR); // this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, Material.AIR);
@ -331,6 +332,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
} }
} }
@SuppressWarnings("deprecation") // Needed for Spigot compatibility
@Override @Override
public void kick(final String message) { public void kick(final String message) {
this.player.kickPlayer(message); this.player.kickPlayer(message);

View File

@ -199,7 +199,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
} }
} }
if (localChunk.getTiles().size() > 0) { if (localChunk.getTiles().size() > 0) {
localChunk.getTiles().forEach(((blockVector3, tag) -> { localChunk.getTiles().forEach((blockVector3, tag) -> {
try { try {
BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag); BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag);
getWorld().setBlock(blockVector3, block, noSideEffectSet); getWorld().setBlock(blockVector3, block, noSideEffectSet);
@ -207,7 +207,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
StateWrapper sw = new StateWrapper(tag); StateWrapper sw = new StateWrapper(tag);
sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ()); sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
} }
})); });
} }
if (localChunk.getEntities().size() > 0) { if (localChunk.getEntities().size() > 0) {
localChunk.getEntities().forEach((location, entity) -> getWorld().createEntity(location, entity)); localChunk.getEntities().forEach((location, entity) -> getWorld().createEntity(location, entity));

View File

@ -166,6 +166,7 @@ public class StateWrapper {
return str; return str;
} }
@SuppressWarnings("deprecation") // #setLine is needed for Spigot compatibility
public boolean restoreTag(String worldName, int x, int y, int z) { public boolean restoreTag(String worldName, int x, int y, int z) {
if (this.tag == null) { if (this.tag == null) {
return false; return false;

View File

@ -77,6 +77,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
return stack; return stack;
} }
@SuppressWarnings("deprecation") // Paper deprecation
@Override @Override
public void open(PlotInventory inv) { public void open(PlotInventory inv) {
BukkitPlayer bp = (BukkitPlayer) inv.getPlayer(); BukkitPlayer bp = (BukkitPlayer) inv.getPlayer();
@ -113,6 +114,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
bp.player.updateInventory(); bp.player.updateInventory();
} }
@SuppressWarnings("deprecation") // Paper deprecation
public PlotItemStack getItem(ItemStack item) { public PlotItemStack getItem(ItemStack item) {
if (item == null) { if (item == null) {
return null; return null;
@ -145,6 +147,7 @@ public class BukkitInventoryUtil extends InventoryUtil {
.toArray(PlotItemStack[]::new); .toArray(PlotItemStack[]::new);
} }
@SuppressWarnings("deprecation") // #getTitle is needed for Spigot compatibility
@Override @Override
public boolean isOpen(PlotInventory plotInventory) { public boolean isOpen(PlotInventory plotInventory) {
if (!plotInventory.isOpen()) { if (!plotInventory.isOpen()) {

View File

@ -61,6 +61,7 @@ public class UpdateUtility implements Listener {
internalVersion = PlotSquared.get().getVersion(); internalVersion = PlotSquared.get().getVersion();
} }
@SuppressWarnings({"deprecation", "DefaultCharset"}) // Suppress Json deprecation, we can't use features from gson 2.8.1 and newer yet
public void updateChecker() { public void updateChecker() {
task = Bukkit.getScheduler().runTaskTimerAsynchronously(this.javaPlugin, () -> { task = Bukkit.getScheduler().runTaskTimerAsynchronously(this.javaPlugin, () -> {
try { try {
@ -68,7 +69,7 @@ public class UpdateUtility implements Listener {
"https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506") "https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506")
.openConnection(); .openConnection();
connection.setRequestMethod("GET"); connection.setRequestMethod("GET");
JsonObject result = (new JsonParser()) JsonObject result = new JsonParser()
.parse(new JsonReader(new InputStreamReader(connection.getInputStream()))) .parse(new JsonReader(new InputStreamReader(connection.getInputStream())))
.getAsJsonObject(); .getAsJsonObject();
spigotVersion = result.get("current_version").getAsString(); spigotVersion = result.get("current_version").getAsString();
@ -91,7 +92,7 @@ public class UpdateUtility implements Listener {
notify = false; notify = false;
LOGGER.info("Congratulations! You are running the latest PlotSquared version"); LOGGER.info("Congratulations! You are running the latest PlotSquared version");
} }
}, 0L, Settings.UpdateChecker.POLL_RATE * 60 * 20); }, 0L, (long) Settings.UpdateChecker.POLL_RATE * 60 * 20);
} }
private void cancelTask() { private void cancelTask() {

View File

@ -75,6 +75,7 @@ public class FaweSchematicHandler extends SchematicHandler {
return delegate.save(tag, path); return delegate.save(tag, path);
} }
@SuppressWarnings("removal") // Just the override
@Override @Override
public void upload(final CompoundTag tag, final UUID uuid, final String file, final RunnableVal<URL> whenDone) { public void upload(final CompoundTag tag, final UUID uuid, final String file, final RunnableVal<URL> whenDone) {
delegate.upload(tag, uuid, file, whenDone); delegate.upload(tag, uuid, file, whenDone);

View File

@ -53,7 +53,7 @@ public abstract class MetaDataAccess<T> implements AutoCloseable {
this.lockAccess = lockAccess; this.lockAccess = lockAccess;
} }
@SuppressWarnings("ALL") @SuppressWarnings("unchecked")
private static <E extends Throwable> void sneakyThrow(final Throwable e) throws E { private static <E extends Throwable> void sneakyThrow(final Throwable e) throws E {
throw (E) e; throw (E) e;
} }

View File

@ -96,7 +96,7 @@ public class FlagContainer {
} }
/** /**
* Cast a plot flag with wildcard parameters into a parametrisized * Cast a plot flag with wildcard parameters into a parametrized
* PlotFlag. This is an unsafe operation, and should only be performed * PlotFlag. This is an unsafe operation, and should only be performed
* if the generic parameters are known beforehand. * if the generic parameters are known beforehand.
* *
@ -105,7 +105,7 @@ public class FlagContainer {
* @param <T> Flag type * @param <T> Flag type
* @return Casted flag * @return Casted flag
*/ */
@SuppressWarnings("ALL") @SuppressWarnings("unchecked")
public static <V, T extends PlotFlag<V, ?>> T castUnsafe( public static <V, T extends PlotFlag<V, ?>> T castUnsafe(
final PlotFlag<?, ?> flag final PlotFlag<?, ?> flag
) { ) {
@ -181,6 +181,7 @@ public class FlagContainer {
* @param <V> flag value type * @param <V> flag value type
* @return value of flag removed * @return value of flag removed
*/ */
@SuppressWarnings("unchecked")
public <V, T extends PlotFlag<V, ?>> V removeFlag(final T flag) { public <V, T extends PlotFlag<V, ?>> V removeFlag(final T flag) {
final Object value = this.flagMap.remove(flag.getClass()); final Object value = this.flagMap.remove(flag.getClass());
if (this.plotFlagUpdateHandler != null) { if (this.plotFlagUpdateHandler != null) {

View File

@ -73,6 +73,7 @@ public class EntityUtil {
return i; return i;
} }
@SuppressWarnings("unchecked")
public static boolean checkEntity(Plot plot, PlotFlag<Integer, ?>... flags) { public static boolean checkEntity(Plot plot, PlotFlag<Integer, ?>... flags) {
if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
return true; return true;