From 03cf5851210193538a6f308735c6ae9203ce9b1a Mon Sep 17 00:00:00 2001 From: themode Date: Mon, 7 Mar 2022 22:18:03 +0100 Subject: [PATCH] Unnecessary null check --- .../java/net/minestom/server/instance/block/BlockImpl.java | 5 ++--- src/test/java/net/minestom/server/instance/BlockTest.java | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/block/BlockImpl.java b/src/main/java/net/minestom/server/instance/block/BlockImpl.java index e652de81a..92a4e5839 100644 --- a/src/main/java/net/minestom/server/instance/block/BlockImpl.java +++ b/src/main/java/net/minestom/server/instance/block/BlockImpl.java @@ -202,9 +202,8 @@ record BlockImpl(@NotNull Registry.BlockEntry registry, private Block compute(byte[] properties) { if (Arrays.equals(propertiesArray, properties)) return this; - BlockImpl block = possibleProperties().get(new PropertiesHolder(properties)); - if (block == null) - throw new IllegalArgumentException("Invalid properties: " + Arrays.toString(properties) + " for block " + this); + final BlockImpl block = possibleProperties().get(new PropertiesHolder(properties)); + assert block != null; return nbt == null && handler == null ? block : new BlockImpl(block.registry(), block.propertiesArray, nbt, handler); } diff --git a/src/test/java/net/minestom/server/instance/BlockTest.java b/src/test/java/net/minestom/server/instance/BlockTest.java index 3559db85a..62cbec600 100644 --- a/src/test/java/net/minestom/server/instance/BlockTest.java +++ b/src/test/java/net/minestom/server/instance/BlockTest.java @@ -33,7 +33,7 @@ public class BlockTest { } @Test - public void testProperty() { + public void validProperties() { Block block = Block.CHEST; assertEquals(block.properties(), Objects.requireNonNull(Block.fromBlockId(block.id())).properties()); @@ -48,8 +48,13 @@ public class BlockTest { assertEquals(block.withProperty("facing", "north").getProperty("facing"), "north"); assertNotEquals(block.withProperty("facing", "north"), block.withProperty("facing", "south")); + } + @Test + public void invalidProperties() { + Block block = Block.CHEST; assertThrows(Exception.class, () -> block.withProperty("random", "randomKey")); + assertThrows(Exception.class, () -> block.withProperties(Map.of("random", "randomKey"))); } @Test