From 827f46566cd55bd06d8fc9064cc0b5ed26676e27 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 20 Jan 2022 12:39:40 +0100 Subject: [PATCH] draft: Address false positives in code style issues (#3461) * chore: Address false positive code style issues * chore: More work * More work --- .lift.toml | 4 ++++ .../src/main/java/com/plotsquared/bukkit/BukkitPlatform.java | 5 ++--- .../plotsquared/bukkit/entity/ReplicatingEntityWrapper.java | 1 + .../com/plotsquared/bukkit/inject/WorldManagerModule.java | 1 + .../com/plotsquared/bukkit/listener/PaperListener113.java | 2 +- .../com/plotsquared/bukkit/listener/PlayerEventListener.java | 3 +++ .../com/plotsquared/bukkit/listener/SingleWorldListener.java | 1 - .../java/com/plotsquared/bukkit/player/BukkitPlayer.java | 4 +++- .../com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java | 4 ++-- .../java/com/plotsquared/bukkit/schematic/StateWrapper.java | 1 + .../com/plotsquared/bukkit/util/BukkitInventoryUtil.java | 3 +++ .../main/java/com/plotsquared/bukkit/util/UpdateUtility.java | 5 +++-- .../plotsquared/bukkit/util/fawe/FaweSchematicHandler.java | 1 + .../java/com/plotsquared/core/player/MetaDataAccess.java | 2 +- .../java/com/plotsquared/core/plot/flag/FlagContainer.java | 5 +++-- Core/src/main/java/com/plotsquared/core/util/EntityUtil.java | 1 + 16 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 .lift.toml diff --git a/.lift.toml b/.lift.toml new file mode 100644 index 000000000..cee7a27a1 --- /dev/null +++ b/.lift.toml @@ -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"] diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index a3350e8e7..7a7569f78 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -218,6 +218,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl private PlatformWorldManager worldManager; private Locale serverLocale; + @SuppressWarnings("StringSplitter") @Override public int @NonNull [] serverVersion() { if (this.version == null) { @@ -970,7 +971,6 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } iterator.remove(); entity.remove(); - continue; } } } else { @@ -982,7 +982,6 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } iterator.remove(); entity.remove(); - continue; } } } @@ -1223,7 +1222,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl @Override @NonNull - @SuppressWarnings("ALL") + @SuppressWarnings("unchecked") public PlayerManager, ? extends Player> playerManager() { return (PlayerManager) injector().getInstance(PlayerManager.class); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java index cdc4da49c..24ff4eec5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java @@ -461,6 +461,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper { this.tamed.tamed = tamed.isTamed(); } + @SuppressWarnings("deprecation") // Paper deprecation @Override public Entity spawn(World world, int xOffset, int zOffset) { Location location = new Location(world, this.getX() + xOffset, this.getY(), this.z + zOffset); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java index 9d5aa50fb..06bf11013 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/WorldManagerModule.java @@ -36,6 +36,7 @@ import org.bukkit.World; public class WorldManagerModule extends AbstractModule { + @SuppressWarnings("removal") // Internal use only @Provides @Singleton PlatformWorldManager provideWorldManager() { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener113.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener113.java index 027ded716..bb3177b1b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener113.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener113.java @@ -36,7 +36,6 @@ import com.plotsquared.core.plot.world.PlotAreaManager; import net.kyori.adventure.text.minimessage.Template; import org.bukkit.block.Banner; import org.bukkit.block.Beacon; -import org.bukkit.block.Bed; import org.bukkit.block.BlockState; import org.bukkit.block.CommandBlock; import org.bukkit.block.Comparator; @@ -51,6 +50,7 @@ import org.bukkit.block.Jukebox; import org.bukkit.block.Sign; import org.bukkit.block.Skull; import org.bukkit.block.Structure; +import org.bukkit.block.data.type.Bed; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockPlaceEvent; import org.checkerframework.checker.nullness.qual.NonNull; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index d45df0e97..e88177b80 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -224,6 +224,7 @@ public class PlayerEventListener extends PlotListener implements Listener { } } + @SuppressWarnings("StringSplitter") @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void playerCommand(PlayerCommandPreprocessEvent event) { String msg = event.getMessage().toLowerCase().replaceAll("/", "").trim(); @@ -379,6 +380,7 @@ public class PlayerEventListener extends PlotListener implements Listener { this.eventDispatcher.doRespawnTask(pp); } + @SuppressWarnings("deprecation") // We explicitly want #getHomeSynchronous here @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onTeleport(PlayerTeleportEvent event) { Player player = event.getPlayer(); @@ -1667,6 +1669,7 @@ public class PlayerEventListener extends PlotListener implements Listener { } } + @SuppressWarnings("deprecation") // #getLocate is needed for Spigot compatibility @EventHandler public void onLocaleChange(final PlayerLocaleChangeEvent event) { // The event is fired before the player is deemed online upon login diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java index 6121351cd..12ef2146e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/SingleWorldListener.java @@ -43,7 +43,6 @@ import java.lang.reflect.Method; import static com.plotsquared.core.util.ReflectionUtils.getRefClass; -@SuppressWarnings("unused") public class SingleWorldListener implements Listener { private final Method methodGetHandleChunk; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index e9cd3cb43..aae86f930 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -162,6 +162,7 @@ public class BukkitPlayer extends PlotPlayer { } } + @SuppressWarnings("StringSplitter") @Override @NonNegative public int hasPermissionRange( @@ -319,7 +320,7 @@ public class BukkitPlayer extends PlotPlayer { if (id == ItemTypes.AIR) { // Let's just stop all the discs because why not? 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); } // this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, Material.AIR); @@ -331,6 +332,7 @@ public class BukkitPlayer extends PlotPlayer { } } + @SuppressWarnings("deprecation") // Needed for Spigot compatibility @Override public void kick(final String message) { this.player.kickPlayer(message); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java index 1e1f10a25..6973dc5d1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitQueueCoordinator.java @@ -199,7 +199,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator { } } if (localChunk.getTiles().size() > 0) { - localChunk.getTiles().forEach(((blockVector3, tag) -> { + localChunk.getTiles().forEach((blockVector3, tag) -> { try { BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag); getWorld().setBlock(blockVector3, block, noSideEffectSet); @@ -207,7 +207,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator { StateWrapper sw = new StateWrapper(tag); sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ()); } - })); + }); } if (localChunk.getEntities().size() > 0) { localChunk.getEntities().forEach((location, entity) -> getWorld().createEntity(location, entity)); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/StateWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/StateWrapper.java index fcd4a85d4..84f8efb4a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/StateWrapper.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/schematic/StateWrapper.java @@ -166,6 +166,7 @@ public class StateWrapper { return str; } + @SuppressWarnings("deprecation") // #setLine is needed for Spigot compatibility public boolean restoreTag(String worldName, int x, int y, int z) { if (this.tag == null) { return false; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java index 89970ae33..8a4e57e78 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitInventoryUtil.java @@ -77,6 +77,7 @@ public class BukkitInventoryUtil extends InventoryUtil { return stack; } + @SuppressWarnings("deprecation") // Paper deprecation @Override public void open(PlotInventory inv) { BukkitPlayer bp = (BukkitPlayer) inv.getPlayer(); @@ -113,6 +114,7 @@ public class BukkitInventoryUtil extends InventoryUtil { bp.player.updateInventory(); } + @SuppressWarnings("deprecation") // Paper deprecation public PlotItemStack getItem(ItemStack item) { if (item == null) { return null; @@ -145,6 +147,7 @@ public class BukkitInventoryUtil extends InventoryUtil { .toArray(PlotItemStack[]::new); } + @SuppressWarnings("deprecation") // #getTitle is needed for Spigot compatibility @Override public boolean isOpen(PlotInventory plotInventory) { if (!plotInventory.isOpen()) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java index 08d7a8190..a6df438e1 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/UpdateUtility.java @@ -61,6 +61,7 @@ public class UpdateUtility implements Listener { 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() { task = Bukkit.getScheduler().runTaskTimerAsynchronously(this.javaPlugin, () -> { try { @@ -68,7 +69,7 @@ public class UpdateUtility implements Listener { "https://api.spigotmc.org/simple/0.1/index.php?action=getResource&id=77506") .openConnection(); connection.setRequestMethod("GET"); - JsonObject result = (new JsonParser()) + JsonObject result = new JsonParser() .parse(new JsonReader(new InputStreamReader(connection.getInputStream()))) .getAsJsonObject(); spigotVersion = result.get("current_version").getAsString(); @@ -91,7 +92,7 @@ public class UpdateUtility implements Listener { notify = false; 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() { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweSchematicHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweSchematicHandler.java index 3b9e984d7..26b1bb2c5 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweSchematicHandler.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweSchematicHandler.java @@ -75,6 +75,7 @@ public class FaweSchematicHandler extends SchematicHandler { return delegate.save(tag, path); } + @SuppressWarnings("removal") // Just the override @Override public void upload(final CompoundTag tag, final UUID uuid, final String file, final RunnableVal whenDone) { delegate.upload(tag, uuid, file, whenDone); diff --git a/Core/src/main/java/com/plotsquared/core/player/MetaDataAccess.java b/Core/src/main/java/com/plotsquared/core/player/MetaDataAccess.java index 98cc5790c..5552c2c9a 100644 --- a/Core/src/main/java/com/plotsquared/core/player/MetaDataAccess.java +++ b/Core/src/main/java/com/plotsquared/core/player/MetaDataAccess.java @@ -53,7 +53,7 @@ public abstract class MetaDataAccess implements AutoCloseable { this.lockAccess = lockAccess; } - @SuppressWarnings("ALL") + @SuppressWarnings("unchecked") private static void sneakyThrow(final Throwable e) throws E { throw (E) e; } diff --git a/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java b/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java index b59c055c5..1a4f95970 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java +++ b/Core/src/main/java/com/plotsquared/core/plot/flag/FlagContainer.java @@ -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 * if the generic parameters are known beforehand. * @@ -105,7 +105,7 @@ public class FlagContainer { * @param Flag type * @return Casted flag */ - @SuppressWarnings("ALL") + @SuppressWarnings("unchecked") public static > T castUnsafe( final PlotFlag flag ) { @@ -181,6 +181,7 @@ public class FlagContainer { * @param flag value type * @return value of flag removed */ + @SuppressWarnings("unchecked") public > V removeFlag(final T flag) { final Object value = this.flagMap.remove(flag.getClass()); if (this.plotFlagUpdateHandler != null) { diff --git a/Core/src/main/java/com/plotsquared/core/util/EntityUtil.java b/Core/src/main/java/com/plotsquared/core/util/EntityUtil.java index a15bf88fe..d547ccfc7 100644 --- a/Core/src/main/java/com/plotsquared/core/util/EntityUtil.java +++ b/Core/src/main/java/com/plotsquared/core/util/EntityUtil.java @@ -73,6 +73,7 @@ public class EntityUtil { return i; } + @SuppressWarnings("unchecked") public static boolean checkEntity(Plot plot, PlotFlag... flags) { if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) { return true;