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 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 PlotPlayer<Player>, ? extends Player> playerManager() {
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();
}
@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);

View File

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

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -162,6 +162,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
}
}
@SuppressWarnings("StringSplitter")
@Override
@NonNegative
public int hasPermissionRange(
@ -319,7 +320,7 @@ public class BukkitPlayer extends PlotPlayer<Player> {
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<Player> {
}
}
@SuppressWarnings("deprecation") // Needed for Spigot compatibility
@Override
public void kick(final String message) {
this.player.kickPlayer(message);

View File

@ -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));

View File

@ -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;

View File

@ -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()) {

View File

@ -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() {

View File

@ -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<URL> whenDone) {
delegate.upload(tag, uuid, file, whenDone);

View File

@ -53,7 +53,7 @@ public abstract class MetaDataAccess<T> implements AutoCloseable {
this.lockAccess = lockAccess;
}
@SuppressWarnings("ALL")
@SuppressWarnings("unchecked")
private static <E extends Throwable> void sneakyThrow(final Throwable e) throws 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
* if the generic parameters are known beforehand.
*
@ -105,7 +105,7 @@ public class FlagContainer {
* @param <T> Flag type
* @return Casted flag
*/
@SuppressWarnings("ALL")
@SuppressWarnings("unchecked")
public static <V, T extends PlotFlag<V, ?>> T castUnsafe(
final PlotFlag<?, ?> flag
) {
@ -181,6 +181,7 @@ public class FlagContainer {
* @param <V> flag value type
* @return value of flag removed
*/
@SuppressWarnings("unchecked")
public <V, T extends PlotFlag<V, ?>> V removeFlag(final T flag) {
final Object value = this.flagMap.remove(flag.getClass());
if (this.plotFlagUpdateHandler != null) {

View File

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